UNPKG

@unito/integration-cli

Version:

Integration CLI

81 lines (80 loc) 2.87 kB
import * as openUrl from 'openurl'; import { Oauth2 } from '../configurationTypes'; import { Environment } from '../resources/globalConfiguration'; export declare const open: typeof openUrl; export declare const HTML_ERROR_MSG: (errorMsg?: string) => string; export declare const HTML_SUCCESS_MSG = "<!doctype html><head><title>Unito</title></head><body style=\"text-align:center\"> Redirected to the CLI successfully </body>"; export interface Oauth2Credentials { clientId: string; clientSecret: string; } export interface AuthorizePayload extends Oauth2Credentials { providerAuthorizationUrl: string; scopes?: string; providerAccessTokenUrl: string; } export interface CallbackPayload { code: string; } export interface Oauth2Response { accessToken: string; refreshToken?: string; } export interface TokenPayload extends Oauth2Credentials { providerTokenUrl: string; code: string; } export type Oauth2Payload = Oauth2; declare class OAuth2Service { private environment; private server; private clientId; private clientSecret; private providerAuthorizationUrl; private tokenUrl; private scopes; private grantType; private requestContentType; private oauth2Response; private serverUrl; private tokenRequestParameters; private refreshRequestParameters; private credentialPayload; /** * Constructs an instance of OAuthHelper. * @param clientId The client ID for your OAuth application. * @param clientSecret The client secret for your OAuth application. * @param authorizationUrl The URL for the authorization endpoint of the provider. * @param scopes The scopes required for the OAuth authorization. * @param providerTokenUrl The URL for the token endpoint of the provider. */ constructor(authorizationInfo: Oauth2Payload, environment?: Environment, credentialPayload?: Record<string, unknown>); /** * Initiate the authorization flow and redirects the user to the provider's authorization page. */ authorize(): Promise<void>; /** * Handles the callback request from the provider and stores the authorization code. * @param req The express Request object. * @param res The express Response object. */ private handleCallback; private parseOAuth2Response; /** * Waits for the authorization code to be set. * @returns A promise that resolves when the code is set. */ callbackIsDone(): Promise<Oauth2Response>; private encodeBody; updateToken(refreshToken: string): Promise<Oauth2Response>; /** * Starts the Express server for handling OAuth callbacks. * @returns The URL of the server. */ startServer(): Promise<string>; /** * Stops the Express server. */ stopServer(): Promise<void>; } export default OAuth2Service;