@adonisjs/ally
Version:
Social authentication provider for AdonisJS
174 lines (173 loc) • 5.34 kB
TypeScript
import type { HttpContext } from '@adonisjs/core/http';
import type { HttpClient } from '@poppinss/oauth-client';
import type { LinkedInToken, LinkedInScopes, ApiRequestContract, LinkedInDriverConfig, RedirectRequestContract } from '../types.ts';
import { Oauth2Driver } from '../abstract_drivers/oauth2.ts';
/**
* LinkedIn OAuth2 driver for authenticating users via LinkedIn.
* Supports fetching user profile information including name, email, and profile picture.
* Note: This driver fetches email separately as it's not included in the basic profile.
*
* @example
* ```ts
* router.get('/linkedin/redirect', ({ ally }) => {
* return ally.use('linkedin').redirect((request) => {
* request.scopes(['r_emailaddress', 'r_liteprofile'])
* })
* })
*
* router.get('/linkedin/callback', async ({ ally }) => {
* const linkedin = ally.use('linkedin')
*
* if (linkedin.accessDenied()) {
* return 'Access was denied'
* }
*
* if (linkedin.stateMisMatch()) {
* return 'State mismatch error'
* }
*
* if (linkedin.hasError()) {
* return linkedin.getError()
* }
*
* const user = await linkedin.user()
* return user
* })
* ```
*/
export declare class LinkedInDriver extends Oauth2Driver<LinkedInToken, LinkedInScopes> {
config: LinkedInDriverConfig;
/**
* LinkedIn token endpoint URL.
*/
protected accessTokenUrl: string;
/**
* LinkedIn authorization endpoint URL.
*/
protected authorizeUrl: string;
/**
* LinkedIn profile endpoint URL.
*/
protected userInfoUrl: string;
/**
* LinkedIn email endpoint URL.
*/
protected userEmailUrl: string;
/**
* The param name for the authorization code
*/
protected codeParamName: string;
/**
* The param name for the error
*/
protected errorParamName: string;
/**
* Cookie name for storing the "linkedin_oauth_state"
*/
protected stateCookieName: string;
/**
* Parameter name to be used for sending and receiving the state
* from linkedin
*/
protected stateParamName: string;
/**
* Parameter name for defining the scopes
*/
protected scopeParamName: string;
/**
* Scopes separator
*/
protected scopesSeparator: string;
/**
* @param ctx - The HTTP context
* @param config - Configuration for the LinkedIn driver
*/
constructor(ctx: HttpContext, config: LinkedInDriverConfig);
/**
* Configures the redirect request with default scopes.
*
* @param request - The redirect request to configure
*/
protected configureRedirectRequest(request: RedirectRequestContract<LinkedInScopes>): void;
/**
* Creates an authenticated HTTP request with the proper authorization
* header for LinkedIn API calls.
*
* @param url - The API endpoint URL
* @param token - The access token
*/
protected getAuthenticatedRequest(url: string, token: string): HttpClient;
/**
* Fetches the authenticated user's profile information from the LinkedIn API.
*
* @param token - The access token
* @param callback - Optional callback to customize the API request
*/
protected getUserInfo(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
id: any;
nickName: any;
name: string;
avatarUrl: string;
original: any;
}>;
/**
* Fetches the user's email address from the LinkedIn API.
* Requires the 'r_emailaddress' scope.
*
* @param token - The access token
* @param callback - Optional callback to customize the API request
*/
protected getUserEmail(token: string, callback?: (request: ApiRequestContract) => void): Promise<any>;
/**
* Check if the error from the callback indicates that the user
* denied authorization or cancelled the login.
*/
accessDenied(): boolean;
/**
* Get the authenticated user's profile and email information using
* the authorization code from the callback request.
*
* @param callback - Optional callback to customize the API request
*
* @example
* ```ts
* const user = await ally.use('linkedin').user()
* console.log(user.name, user.email)
* ```
*/
user(callback?: (request: ApiRequestContract) => void): Promise<{
email: any;
emailVerificationState: "unsupported";
token: LinkedInToken;
id: any;
nickName: any;
name: string;
avatarUrl: string;
original: any;
}>;
/**
* Get the user's profile and email information using an existing
* access token.
*
* @param token - The LinkedIn access token
* @param callback - Optional callback to customize the API request
*
* @example
* ```ts
* const user = await ally.use('linkedin').userFromToken(accessToken)
* ```
*/
userFromToken(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
email: any;
emailVerificationState: "unsupported";
token: {
token: string;
type: "bearer";
};
id: any;
nickName: any;
name: string;
avatarUrl: string;
original: any;
}>;
}