@openauth/facebook
Version:
OAuth facebook library.
56 lines • 2.21 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FacebookOAuth = void 0;
const core_1 = require("@openauth/core");
const facebook_client_1 = require("./facebook-client");
class FacebookOAuth extends core_1.OAuth2 {
constructor(options) {
var _a;
super(options);
this.version = (_a = options.version) !== null && _a !== void 0 ? _a : 'v11.0';
}
apiBaseUri() {
return `https://graph.facebook.com/${this.version}`;
}
authRequestUri() {
return `https://www.facebook.com/${this.version}/dialog/oauth`;
}
accessTokenRequestUri() {
return 'oauth/access_token';
}
createClient(accessToken) {
return new facebook_client_1.FacebookClient({
baseUri: this.apiBaseUri(),
fetch: this._fetch,
accessToken,
});
}
getAuthUser(accessToken) {
return __awaiter(this, void 0, void 0, function* () {
const { data } = yield this.getClient(accessToken).get({
path: 'me',
query: {
fields: 'id,email,name',
},
});
return {
id: data.id,
name: data.name,
email: data.email,
avatar: `https://graph.facebook.com/${this.version}/${data.id}/picture?type=normal`,
raw: data,
};
});
}
}
exports.FacebookOAuth = FacebookOAuth;
//# sourceMappingURL=facebook-oauth.js.map