UNPKG

@adonisjs/ally

Version:

Social authentication provider for AdonisJS

101 lines (100 loc) 2.93 kB
import { Oauth1Driver } from "../../chunk-VHORNQLN.js"; import "../../chunk-N72DEJC2.js"; import "../../chunk-PZ5AY32C.js"; // src/drivers/twitter.ts var TwitterDriver = class extends Oauth1Driver { constructor(ctx, config) { super(ctx, config); this.ctx = ctx; this.config = config; this.loadState(); } requestTokenUrl = "https://api.twitter.com/oauth/request_token"; authorizeUrl = "https://api.twitter.com/oauth/authenticate"; accessTokenUrl = "https://api.twitter.com/oauth/access_token"; userInfoUrl = "https://api.twitter.com/1.1/account/verify_credentials.json"; /** * The query string param name for the error. */ errorParamName = "error"; /** * The query string param name for the "oauth_verifier". Used * for both the post redirect value access and during the * time of generating the access token */ oauthTokenVerifierName = "oauth_verifier"; /** * Cookie name for storing the oauth_token. The cookie * name for storing oauth_token_secret is derived * from this property */ oauthTokenCookieName = "twitter_oauth_token"; /** * Param name for defined the "oauth_token" pre redirect * and also used post redirect for reading the "oauth_token" * value */ oauthTokenParamName = "oauth_token"; /** * Twitter doesn't support scopes */ scopeParamName = ""; scopesSeparator = " "; /** * Returns user info */ async getUserInfo(token, secret, callback) { const requestToken = { token, secret }; const userInfoUrl = this.config.userInfoUrl || this.userInfoUrl; const user = await this.makeSignedRequest(userInfoUrl, "get", requestToken, (request) => { request.param("include_email", true); request["parseAs"]("json"); if (typeof callback === "function") { callback(request); } }); return { id: user.id_str, nickName: user.screen_name, name: user.name || user.screen_name, email: user.email, emailVerificationState: "unsupported", avatarUrl: user.profile_image_url_https.replace("_normal.jpg", "_400x400.jpg"), original: user }; } /** * Returns details for the authorized user */ async user(callback) { const token = await this.accessToken(); const userInfo = await this.getUserInfo(token.token, token.secret, callback); return { ...userInfo, token }; } /** * Finds the user info from the "oauth_token" and "oauth_token_secret" * access from the access token. */ async userFromTokenAndSecret(token, secret, callback) { const userInfo = await this.getUserInfo(token, secret, callback); return { ...userInfo, token: { token, secret } }; } /** * Find if the current error code is for access denied */ accessDenied() { return this.ctx.request.input("denied"); } }; export { TwitterDriver }; //# sourceMappingURL=twitter.js.map