UNPKG

adonis-ally-vk

Version:
134 lines (133 loc) 4.87 kB
/// <reference types="@adonisjs/ally" /> /// <reference types="@adonisjs/http-server/build/adonis-typings" /> import type { AllyUserContract, LiteralStringUnion } from '@ioc:Adonis/Addons/Ally'; import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; import { Oauth2Driver, ApiRequest, RedirectRequest } from '@adonisjs/ally/build/standalone'; /** * Define the access token object properties in this type. It * must have "token" and "type" and you are free to add * more properties. */ export declare type VkAccessToken = { token: string; type: 'bearer'; email: string; expires_in: number; user_id: number; }; /** * Driver scopes * See https://vk.com/dev/permissions */ export declare type VkScopes = 'notify' | 'friends' | 'photos' | 'audio' | 'video' | 'stories' | 'pages' | 'status' | 'notes' | 'messages' | 'wall' | 'ads' | 'offline' | 'docs' | 'groups' | 'notifications' | 'stats' | 'email' | 'market'; /** * Driver config */ export declare type VkDriverConfig = { driver: 'vk'; clientId: string; clientSecret: string; callbackUrl: string; authorizeUrl?: string; accessTokenUrl?: string; userInfoUrl?: string; scopes?: LiteralStringUnion<VkScopes>[]; display?: 'page' | 'popup'; /** * A list available fields * See https://vk.com/dev/objects/user */ fields?: string[]; }; /** * Vkontakte driver to login user via vk.com */ export declare class VkDriver extends Oauth2Driver<VkAccessToken, VkScopes> { config: VkDriverConfig; /** * The version of api vk.com */ protected apiVersion: string; /** * The URL for the redirect request. The user will be redirected on this page * to authorize the request. */ protected authorizeUrl: string; /** * The URL to hit to exchange the authorization code for the access token */ protected accessTokenUrl: string; /** * The URL to hit to get the user details */ protected userInfoUrl: string; /** * The param name for the authorization code. Read the documentation of your oauth * provider and update the param name to match the query string field name in * which the oauth provider sends the authorization_code post redirect. */ protected codeParamName: string; /** * The param name for the error. Read the documentation of your oauth provider and update * the param name to match the query string field name in which the oauth provider sends * the error post redirect */ protected errorParamName: string; /** * Cookie name for storing the CSRF token. Make sure it is always unique. So a better * approach is to prefix the oauth provider name to `oauth_state` value. */ protected stateCookieName: string; /** * Parameter name to be used for sending and receiving the state from. * Read the documentation of your oauth provider and update the param * name to match the query string used by the provider for exchanging * the state. */ protected stateParamName: string; /** * Parameter name for sending the scopes to the oauth provider. */ protected scopeParamName: string; /** * The separator indentifier for defining multiple scopes */ protected scopesSeparator: string; constructor(ctx: HttpContextContract, config: VkDriverConfig); /** * Optionally configure the authorization redirect request. The actual request * is made by the base implementation of "Oauth2" driver and this is a * hook to pre-configure the request. */ protected configureRedirectRequest(request: RedirectRequest<VkScopes>): void; /** * Optionally configure the access token request. The actual request is made by * the base implementation of "Oauth2" driver and this is a hook to pre-configure * the request */ /** * Update the implementation to tell if the error received during redirect * means "ACCESS DENIED". */ accessDenied(): boolean; /** * Get the user details by query the provider API. This method must return * the access token and the user details both. */ user(callback?: (request: ApiRequest) => void): Promise<AllyUserContract<VkAccessToken>>; /** * Finds the user by the access token */ userFromToken(accessToken: string, callback?: (request: ApiRequest) => void): Promise<AllyUserContract<{ token: string; type: 'bearer'; }>>; /** * Returns the request with access_token and version api */ protected getAuthenticatedRequest(token: string): ApiRequest; /** * Returns a user info */ protected getUserInfo(token: string, callback?: (request: ApiRequest) => void): Promise<Omit<AllyUserContract<VkAccessToken>, 'email' | 'token'>>; }