aws-delivlib
Version:
A fabulous library for defining continuous pipelines for building, testing and releasing code libraries.
39 lines (38 loc) • 953 B
JavaScript
import { request as defaultRequest } from "@octokit/request";
import btoa from "btoa-lite";
async function scopeToken(options) {
const {
request: optionsRequest,
clientType,
clientId,
clientSecret,
token,
...requestOptions
} = options;
const request = optionsRequest || /* istanbul ignore next: we always pass a custom request in tests */
defaultRequest;
const response = await request(
"POST /applications/{client_id}/token/scoped",
{
headers: {
authorization: `basic ${btoa(`${clientId}:${clientSecret}`)}`
},
client_id: clientId,
access_token: token,
...requestOptions
}
);
const authentication = Object.assign(
{
clientType,
clientId,
clientSecret,
token: response.data.token
},
response.data.expires_at ? { expiresAt: response.data.expires_at } : {}
);
return { ...response, authentication };
}
export {
scopeToken
};