GitHub
For usage, see OAuth 2.0 provider.
import { GitHub } from "arctic";
const github = new GitHub(clientId, clientSecret, {
// optional
redirectURI, // required when multiple redirect URIs are defined
enterpriseDomain: "https://example.com" // the base URL of your GitHub Enterprise Server instance
});
const url: URL = await github.createAuthorizationURL(state, {
// optional
scopes
});
const tokens: GitHubTokens = await github.validateAuthorizationCode(code);
Get user profile
Use the /user
endpoint.
const response = await fetch("https://api.github.com/user", {
headers: {
Authorization: `Bearer ${tokens.accessToken}`
}
});
const user = await response.json();
Get email
Add the email
scope and use the /user/emails
endpoint.
const url = await github.createAuthorizationURL(state, {
scopes: ["user:email"]
});
const tokens = await github.validateAuthorizationCode(code);
const response = await fetch("https://api.github.com/user/emails", {
headers: {
Authorization: `Bearer ${tokens.accessToken}`
}
});
const emails = await response.json();