Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* istanbul ignore if */
if (typeof clientSecret === 'undefined' || typeof proxy === 'undefined') {
throw new Error('clientSecret and proxy is required for Gitee V5')
}
this.baseURL = baseURL
this.owner = owner
this.repo = repo
this.labels = labels
this.clientId = clientId
this.clientSecret = clientSecret
this.state = state
this.proxy = proxy
this.$http = axios.create({
baseURL: concatURL(baseURL, 'api/v5'),
})
this.$http.interceptors.response.use(response => response, error => {
if (error.response.data && error.response.data.message) {
error.message = error.response.data.message
}
return Promise.reject(error)
})
}
async getAccessToken ({
code,
}: {
code: string
}): Promise {
/**
* access_token api does not support cors
* @see https://github.com/isaacs/github/issues/330
*/
const originalURL = concatURL(this.baseURL, 'login/oauth/access_token')
const proxyURL = typeof this.proxy === 'function'
? this.proxy(originalURL)
: this.proxy
const { data } = await this.$http.post(proxyURL, {
client_id: this.clientId,
client_secret: this.clientSecret,
code,
/**
* useless but mentioned in docs
*/
// redirect_uri: window.location.href,
// state: this.state,
}, {
headers: {
'Accept': 'application/json',
},
redirectAuth (): void {
window.location.href = buildURL(concatURL(this.baseURL, 'site/oauth2/authorize'), {
client_id: this.clientId,
redirect_uri: window.location.href,
response_type: 'token',
state: this.state,
})
}
private apiURL (url) {
return typeof this.proxy === 'function' ? this.proxy(concatURL(this.baseURL, `api/v1/${url}`)) : url
}
async getAccessToken ({
code,
}: {
code: string
}): Promise {
const originalURL = concatURL(this.baseURL, 'login/oauth/access_token')
const proxyURL = typeof this.proxy === 'function'
? this.proxy(originalURL)
: this.proxy
/**
* JSON does not work
*
* @see https://github.com/go-gitea/gitea/issues/6624
*/
const { data } = await this.$http.post(proxyURL, buildQuery({
'client_id': this.clientId,
'client_secret': this.clientSecret,
'code': code,
'grant_type': 'authorization_code',
'redirect_uri': window.location.href,
}), {
headers: {
export function normalizeUser (user: any, baseURL: string): VssueAPI.User {
return {
username: user.login,
avatar: user.avatar_url,
homepage: concatURL(baseURL, user.login),
}
}
redirectAuth (): void {
window.location.href = buildURL(concatURL(this.baseURL, 'oauth/authorize'), {
client_id: this.clientId,
redirect_uri: window.location.href,
scope: 'user_info issues notes',
response_type: 'code',
state: this.state,
})
}
redirectAuth (): void {
window.location.href = buildURL(concatURL(this.baseURL, 'login/oauth/authorize'), {
client_id: this.clientId,
redirect_uri: window.location.href,
scope: 'public_repo',
state: this.state,
})
}