fitbit-api-client
Version:
## ⚠️ This SDK is not ready for production
53 lines • 1.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OAuthApi = void 0;
const base_api_1 = require("./base.api");
const models_1 = require("../models");
class OAuthApi extends base_api_1.BaseApi {
constructor() {
super(...arguments);
this.scope = null;
}
async postTokenRefresh(request, options) {
const { refreshToken, clientId, clientSecret, expiresIn } = request;
const body = new URLSearchParams({
refresh_token: refreshToken,
grant_type: 'refresh_token',
...(expiresIn ? { expires_in: expiresIn.toString() } : {}),
...(clientSecret ? {} : { client_id: clientId }),
});
const headers = {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
};
if (clientSecret) {
headers['Authorization'] =
`Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`;
}
const res = await this.post('/oauth2/token', body, {
...options,
headers,
});
return (0, models_1.AuthTokenFromJson)(res);
}
async postAuthorization({ clientId, clientSecret, redirectUrl, codeVerifier, code, }) {
const body = new URLSearchParams({
client_id: clientId,
grant_type: 'authorization_code',
code,
code_verifier: codeVerifier,
});
if (redirectUrl) {
body.append('redirect_uri', redirectUrl);
}
const headers = {
Authorization: 'Basic ' +
Buffer.from(`${clientId}:${clientSecret}`).toString('base64'),
'Content-Type': 'application/x-www-form-urlencoded',
};
const res = await this.post('/oauth2/token', body, { headers });
return (0, models_1.AuthTokenFromJson)(res);
}
}
exports.OAuthApi = OAuthApi;
//# sourceMappingURL=oauth.api.js.map