Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).then((code: string) => {
return Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL)
})
.then((tokenData: OAuth.TokenData) => {
private static async auth(event: Event, code: string, instance: string, clientId: string, clientSecret: string, redirectUri: string) {
let tokenData: Partial<{ accessToken: string }>
try {
tokenData = await Mastodon.fetchAccessToken(clientId, clientSecret, code, "https://" + instance, redirectUri)
} catch (err) {
let error: Error = err
error.name = "ERROR_CONNECTION"
event.sender.send(`login-complete`, undefined, error)
return
}
if (tokenData.accessToken === undefined) {
let error = new Error("Failed to get access token.")
error.name = "ERROR_GET_TOKEN"
event.sender.send(`login-complete`, undefined, error)
return
}
const client = Client.createAuthClient('http', instance, tokenData.accessToken)
async getAccessToken(code: string, proxy: ProxyConfig | false): Promise {
const tokenData: OAuth.TokenData = await Mastodon.fetchAccessToken(
this.clientId,
this.clientSecret,
code,
this.baseURL,
'urn:ietf:wg:oauth:2.0:oob',
proxy
)
const search = {
baseURL: this.baseURL,
domain: this.domain,
clientId: this.clientId,
clientSecret: this.clientSecret
}
const rec = await this.db.searchAccount(search)
const accessToken = tokenData.accessToken
const refreshToken = tokenData.refreshToken