@openauth/facebook
Version:
Facebook OAuth library
63 lines (62 loc) • 2.2 kB
JavaScript
import { OAuth20, OAuthError } from "@openauth/core";
export class FacebookOAuth extends 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 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,
};
}
}