@openauth/facebook
Version:
Facebook OAuth library
67 lines (66 loc) • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FacebookOAuth = void 0;
const core_1 = require("@openauth/core");
class FacebookOAuth extends core_1.OAuth20 {
get authRequestUri() {
return `https://www.facebook.com/${this.version}/dialog/oauth`;
}
get accessTokenRequestUri() {
return `https://graph.facebook.com/${this.version}/oauth/access_token`;
}
get userProfileUri() {
return `https://graph.facebook.com/${this.version}/me?${new URLSearchParams({ fields: "id,email,name" })}`;
}
constructor(options) {
super(options);
Object.defineProperty(this, "jwksUri", {
enumerable: true,
configurable: true,
writable: true,
value: "https://www.facebook.com/.well-known/oauth/openid/jwks"
});
Object.defineProperty(this, "jwtIssuer", {
enumerable: true,
configurable: true,
writable: true,
value: "https://www.facebook.com"
});
Object.defineProperty(this, "scopes", {
enumerable: true,
configurable: true,
writable: true,
value: ["email"]
});
Object.defineProperty(this, "scopeSeparator", {
enumerable: true,
configurable: true,
writable: true,
value: ","
});
Object.defineProperty(this, "version", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.version = options.version ?? "v25.0";
}
createErrorFromHttpClientError(e) {
if (e.data !== null && typeof e.data === "object" && "error" in e.data) {
const { error: { message, type, ...extra } = {} } = e.data;
return new core_1.OAuthError(message || "Error occurred", type, extra);
}
return super.createErrorFromHttpClientError(e);
}
mapDataToUserProfile(data) {
return {
id: data.id,
...data.name && { name: data.name },
...data.email && { email: data.email },
picture: `https://graph.facebook.com/${this.version}/${data.id}/picture?type=normal`,
raw: data,
};
}
}
exports.FacebookOAuth = FacebookOAuth;