Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
return data.access_token
}
async handleAuth (): Promise {
const hash = parseQuery(window.location.hash.slice(1))
if (!hash.access_token || hash.state !== this.state) {
return null
}
const accessToken = hash.access_token
delete hash.access_token
delete hash.token_type
delete hash.expires_in
delete hash.state
const hashString = buildQuery(hash)
const newHash = hashString ? `#${hashString}` : ''
const replaceURL = `${getCleanURL(window.location.href)}${window.location.search}${newHash}`
window.history.replaceState(null, '', replaceURL)
return accessToken
}
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this.$http.post("https://cors-anywhere.herokuapp.com/" + 'https://bitbucket.org/site/oauth2/access_token', buildQuery({
grant_type: 'authorization_code',
redirect_uri: window.location.href,
code: code,
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
auth: {
username: this.clientId,
password: this.clientSecret,
},
})];
case 1:
response = _b.sent();
accessToken = response.data.access_token;
return [2 /*return*/, accessToken];
async handleAuth (): Promise {
const hash = parseQuery(window.location.hash.slice(1))
if (!hash.access_token || hash.state !== this.state) {
return null
}
const accessToken = hash.access_token
delete hash.access_token
delete hash.token_type
delete hash.expires_in
delete hash.state
delete hash.scopes
const hashString = buildQuery(hash)
const newHash = hashString ? `#${hashString}` : ''
const replaceURL = `${getCleanURL(window.location.href)}${window.location.search}${newHash}`
window.history.replaceState(null, '', replaceURL)
return accessToken
}