Last active
March 22, 2022 06:04
-
-
Save hojongs/f623ecfe2dcbf3efb2f9e7672cb2c13e to your computer and use it in GitHub Desktop.
Typescript(Javascript): twitch client credentials flow using simple-oauth2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/lelylan/simple-oauth2 | |
// https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#oauth-client-credentials-flow | |
async function getAccessToken(): Promise<AccessToken | null> { | |
const client = new ClientCredentials({ | |
client: { | |
id: "client-id", | |
secret: "client-secret", | |
}, | |
auth: { | |
tokenHost: "https://id.twitch.tv", | |
tokenPath: "/oauth2/token", | |
}, | |
options: { | |
authorizationMethod: "body", | |
}, | |
}); | |
try { | |
return await client.getToken({ | |
scope: ["<scope>"], | |
}); | |
} catch (error: any) { | |
console.log("Access Token error", error.message); | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output