feat: add OAuth 2.0 support

This commit is contained in:
liyasthomas
2021-08-25 21:30:13 +05:30
parent 8796cec493
commit fedc230c9f
7 changed files with 250 additions and 18 deletions

View File

@@ -198,7 +198,7 @@ const tokenRequest = async ({
* Handle the redirect back from the authorization server and
* get an access token from the token endpoint
*
* @returns {Object}
* @returns {Promise<any | void>}
*/
const oauthRedirect = () => {
@@ -213,6 +213,7 @@ const oauthRedirect = () => {
// Verify state matches what we set at the beginning
if (getLocalConfig("pkce_state") !== q.state) {
alert("Invalid state")
Promise.reject(tokenResponse)
} else {
try {
// Exchange the authorization code for an access token
@@ -225,6 +226,7 @@ const oauthRedirect = () => {
})
} catch (e) {
console.error(e)
return Promise.reject(tokenResponse)
}
}
// Clean these up since we don't need them anymore
@@ -234,7 +236,7 @@ const oauthRedirect = () => {
removeLocalConfig("client_id")
return tokenResponse
}
return tokenResponse
return Promise.reject(tokenResponse)
}
export { tokenRequest, oauthRedirect }