download
raw
2.06 kB
import { createOAuth2Request, encodeBasicCredentials, sendTokenRequest } from "../request.js";
const authorizationEndpoint = "https://github.com/login/oauth/authorize";
const tokenEndpoint = "https://github.com/login/oauth/access_token";
export class GitHub {
clientId;
clientSecret;
redirectURI;
constructor(clientId, clientSecret, redirectURI) {
this.clientId = clientId;
this.clientSecret = clientSecret;
this.redirectURI = redirectURI;
}
createAuthorizationURL(state, scopes) {
const url = new URL(authorizationEndpoint);
url.searchParams.set("response_type", "code");
url.searchParams.set("client_id", this.clientId);
url.searchParams.set("state", state);
url.searchParams.set("scope", scopes.join(" "));
if (this.redirectURI !== null) {
url.searchParams.set("redirect_uri", this.redirectURI);
}
return url;
}
async validateAuthorizationCode(code) {
const body = new URLSearchParams();
body.set("grant_type", "authorization_code");
body.set("code", code);
if (this.redirectURI !== null) {
body.set("redirect_uri", this.redirectURI);
}
const request = createOAuth2Request(tokenEndpoint, body);
const encodedCredentials = encodeBasicCredentials(this.clientId, this.clientSecret);
request.headers.set("Authorization", `Basic ${encodedCredentials}`);
const tokens = await sendTokenRequest(request);
return tokens;
}
async refreshAccessToken(refreshToken) {
const body = new URLSearchParams();
body.set("grant_type", "refresh_token");
body.set("refresh_token", refreshToken);
const request = createOAuth2Request(tokenEndpoint, body);
const encodedCredentials = encodeBasicCredentials(this.clientId, this.clientSecret);
request.headers.set("Authorization", `Basic ${encodedCredentials}`);
const tokens = await sendTokenRequest(request);
return tokens;
}
}

Xet Storage Details

Size:
2.06 kB
·
Xet hash:
08ae060cf62e251883c8249e58054143417637246a85f568f0115d8d9930cda4

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.