UNPKG

@di-zed/yandex-smart-home

Version:

The Yandex Smart Home skills for the different device types.

133 lines (132 loc) 3.4 kB
/** * @author DiZed Team * @copyright Copyright (c) DiZed Team (https://github.com/di-zed/) */ import { NextFunction, Request, Response } from 'express'; /** * Authorization Controller. */ export default class AuthController { /** * Protect Middleware. * * @param req * @param res * @param next * @returns void */ protect(req: Request, res: Response, next: NextFunction): Promise<void>; /** * GET Method. * Get Login Form. * https://yandex.ru/dev/dialogs/alice/doc/auth/how-it-works.html?lang=en * * @param req * @param res * @param next * @returns void */ login(req: Request, res: Response, next: NextFunction): Promise<void>; /** * POST Method. * Authorization Action. * https://yandex.ru/dev/dialogs/alice/doc/auth/how-it-works.html?lang=en#authorization * * @param req * @param res * @param next * @returns void */ loginPost(req: Request, res: Response, next: NextFunction): Promise<void>; /** * POST Method. * Get Token Information. * https://yandex.ru/dev/dialogs/alice/doc/auth/how-it-works.html?lang=en * * This example shows getting an OAuth token in the web service. * https://yandex.ru/dev/direct/doc/examples-v5/php5-file_get_contents-token.html?lang=en * * @param req * @param res * @param next * @returns Response */ token(req: Request, res: Response, next: NextFunction): Promise<Response | void>; /** * Get Auth Parameters. * * @param data * @returns AuthParams * @protected */ protected getAuthParams(data: any): AuthParams; /** * Is the Authentication Request valid? * * @param authParams * @returns boolean * @protected */ protected isAuthRequestValid(authParams: AuthParams): boolean; /** * Sign Token. * * @param appId * @param userId * @param expiresIn * @returns string * @protected */ protected signToken(appId: number, userId: string | number, expiresIn: string): string; /** * Verify Token. * * @param token * @returns Promise<TokenData> * @protected */ protected verifyToken(token: string): Promise<TokenData>; } /** * Auth Params Type. * https://yandex.ru/dev/dialogs/alice/doc/auth/how-it-works.html?lang=en#authorization */ type AuthParams = { /** * Authorization state. * It is generated by Yandex Dialogs to track the authorization process. * The authorization server must return the same value in this parameter to Yandex Dialogs. */ state: string; /** * The page where the authorized user is redirected (the redirect endpoint). */ redirect_uri: string; /** * Authorization type. Accepts the "code" value. */ response_type: string; /** * The ID of your OAuth app. */ client_id: string; /** * An access scope to be granted to the requested OAuth tokens (the access token scope). * For example: "read", "home:lights". To specify multiple accesses, separate them with "&". */ scope: string; }; /** * The Token Data Type. */ type TokenData = { /** * Application ID. */ appId: number; /** * User ID. */ userId: string | number; }; export {};