Buckets:
| import { createOAuth2Request, sendTokenRequest, sendTokenRevocationRequest } from "../request.js"; | |
| const authorizationEndpoint = "https://account.box.com/api/oauth2/authorize"; | |
| const tokenEndpoint = "https://api.box.com/oauth2/token"; | |
| const tokenRevocationEndpoint = "https://api.box.com/oauth2/revoke"; | |
| export class Box { | |
| 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(" ")); | |
| 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); | |
| body.set("redirect_uri", this.redirectURI); | |
| body.set("client_id", this.clientId); | |
| body.set("client_secret", this.clientSecret); | |
| const request = createOAuth2Request(tokenEndpoint, body); | |
| 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); | |
| body.set("client_id", this.clientId); | |
| body.set("client_secret", this.clientSecret); | |
| const request = createOAuth2Request(tokenEndpoint, body); | |
| const tokens = await sendTokenRequest(request); | |
| return tokens; | |
| } | |
| async revokeToken(token) { | |
| const body = new URLSearchParams(); | |
| body.set("token", token); | |
| body.set("client_id", this.clientId); | |
| body.set("client_secret", this.clientSecret); | |
| const request = createOAuth2Request(tokenRevocationEndpoint, body); | |
| await sendTokenRevocationRequest(request); | |
| } | |
| } | |
Xet Storage Details
- Size:
- 2.21 kB
- Xet hash:
- b87830a7163400b822543177a192b7e2fd3334d0c8f893ea9825e97fb8d91f87
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.