@adonisjs/ally
Version:
Social authentication provider for AdonisJS
170 lines (169 loc) • 5.43 kB
TypeScript
import type { HttpContext } from '@adonisjs/core/http';
import type { HttpClient } from '@poppinss/oauth-client';
import { Oauth2Driver } from '../abstract_drivers/oauth2.ts';
import type { ApiRequestContract, LinkedInOpenidConnectAccessToken, LinkedInOpenidConnectDriverConfig, LinkedInOpenidConnectScopes, Oauth2AccessToken, RedirectRequestContract } from '../types.ts';
/**
* LinkedIn OpenID Connect OAuth2 driver for authenticating users via LinkedIn.
* This driver uses the OpenID Connect protocol for authentication.
* Supports fetching user profile information including name, email, and profile picture.
*
* @example
* ```ts
* router.get('/linkedin/redirect', ({ ally }) => {
* return ally.use('linkedinOpenidConnect').redirect((request) => {
* request.scopes(['openid', 'profile', 'email'])
* })
* })
*
* router.get('/linkedin/callback', async ({ ally }) => {
* const linkedin = ally.use('linkedinOpenidConnect')
*
* 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 LinkedInOpenidConnectDriver extends Oauth2Driver<LinkedInOpenidConnectAccessToken, LinkedInOpenidConnectScopes> {
config: LinkedInOpenidConnectDriverConfig;
/**
* LinkedIn OpenID authorization endpoint URL.
*/
protected authorizeUrl: string;
/**
* LinkedIn OpenID token endpoint URL.
*/
protected accessTokenUrl: string;
/**
* LinkedIn OpenID userinfo endpoint URL.
*/
protected userInfoUrl: 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_openid_connect_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 OpenID Connect driver
*/
constructor(ctx: HttpContext, config: LinkedInOpenidConnectDriverConfig);
/**
* Configures the redirect request with default scopes for OpenID Connect.
*
* @param request - The redirect request to configure
*/
protected configureRedirectRequest(request: RedirectRequestContract<LinkedInOpenidConnectScopes>): 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
* using the OpenID Connect userinfo endpoint.
*
* @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: any;
avatarUrl: any;
email: any;
emailVerificationState: "verified" | "unverified";
original: 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 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('linkedinOpenidConnect').user()
* console.log(user.name, user.email)
* ```
*/
user(callback?: (request: ApiRequestContract) => void): Promise<{
token: {
token: string;
type: "bearer";
expiresIn: number;
expiresAt: Exclude<Oauth2AccessToken["expiresAt"], undefined>;
};
id: any;
nickName: any;
name: any;
avatarUrl: any;
email: any;
emailVerificationState: "verified" | "unverified";
original: any;
}>;
/**
* Get the user's profile 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('linkedinOpenidConnect').userFromToken(accessToken)
* ```
*/
userFromToken(token: string, callback?: (request: ApiRequestContract) => void): Promise<{
token: {
token: string;
type: "bearer";
};
id: any;
nickName: any;
name: any;
avatarUrl: any;
email: any;
emailVerificationState: "verified" | "unverified";
original: any;
}>;
}