@foal/social
Version:
Social authentication for FoalTS
35 lines (34 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GithubProvider = void 0;
// FoalTS
const abstract_provider_service_1 = require("./abstract-provider.service");
const user_info_error_1 = require("./user-info.error");
/**
* Github social provider.
*
* @export
* @class GithubProvider
* @extends {AbstractProvider<GithubAuthParams, never>}
*/
class GithubProvider extends abstract_provider_service_1.AbstractProvider {
configPaths = {
clientId: 'settings.social.github.clientId',
clientSecret: 'settings.social.github.clientSecret',
redirectUri: 'settings.social.github.redirectUri',
};
authEndpoint = 'https://github.com/login/oauth/authorize';
tokenEndpoint = 'https://github.com/login/oauth/access_token';
userInfoEndpoint = 'https://api.github.com/user';
async getUserInfoFromTokens(tokens) {
const response = await fetch(this.userInfoEndpoint, {
headers: { Authorization: `token ${tokens.access_token}` }
});
const body = await response.json();
if (!response.ok) {
throw new user_info_error_1.UserInfoError(body);
}
return body;
}
}
exports.GithubProvider = GithubProvider;