@poppinss/oauth-client
Version:
A framework agnostic package to implement "Login with" flow using OAuth compliant authorization servers.
107 lines (106 loc) • 4.02 kB
TypeScript
import type { Oauth1AccessToken, Oauth1ClientConfig, ApiRequestContract, Oauth1RequestToken, RedirectRequestContract } from '../../types.ts';
import { HttpClient } from '../../http_client.ts';
import { UrlBuilder } from '../../url_builder.ts';
/**
* Generic implementation of Oauth1 three leged authorization flow.
*/
export declare class Oauth1Client<Token extends Oauth1AccessToken> {
options: Oauth1ClientConfig;
constructor(options: Oauth1ClientConfig);
/**
* Define the request token url. Can be overridden by config
*/
protected requestTokenUrl: string;
/**
* Define the authorize url. Can be overridden by config
*/
protected authorizeUrl: string;
/**
* Define the access token url. Can be overridden by config
*/
protected accessTokenUrl: string;
/**
* Get the signature for the request
*/
protected getSignature(baseUrl: string, method: 'get' | 'post', params: Record<string, any>, requestToken?: Oauth1RequestToken): {
params: any;
oauthParams: {
[key: string]: string | number | boolean;
};
oauthHeader: string;
signature: string;
};
/**
* Make a signed request to the authorization server. The request follows
* the Oauth1 spec and generates the Authorization header using the
* [[Oauth1Signature]] class.
*/
protected makeSignedRequest(url: string, method: 'get' | 'post', requestToken?: Oauth1RequestToken, callback?: (request: ApiRequestContract) => void): Promise<any>;
/**
* Configure the redirect request. Invoked before
* the user callback.
*
* The client defaults can be removed using the `clearParam` method
*/
protected configureRedirectRequest(_: RedirectRequestContract): void;
/**
* Configure the access token request. Invoked before
* the user callback.
*
* The client defaults can be removed using the `clearParam` or
* `clearOauth1Param` methods
*/
protected configureAccessTokenRequest(_: ApiRequestContract): void;
/**
* Configure the request token request. Invoked before
* the user callback.
*
* The client defaults can be removed using the `clearParam` or
* `clearOauth1Param` methods
*/
protected configureRequestTokenRequest(_: ApiRequestContract): void;
/**
* Processing the API client response. The child class can overwrite it
* for more control
*/
protected processClientResponse(_: string, client: HttpClient, response: any): any;
/**
* Returns the instance of the HTTP client for internal use
*/
protected httpClient(url: string): HttpClient;
/**
* Returns the instance of the URL builder
*/
protected urlBuilder(url: string): UrlBuilder;
/**
* Verify state and the input value and raise exception if different or missing
*/
verifyState(state: string, inputValue?: string): void;
/**
* Returns the oauth token and secret for the upcoming requests
*/
getRequestToken(callback?: (request: ApiRequestContract) => void): Promise<Oauth1RequestToken>;
/**
* Returns the redirect url for redirecting the user. We don't pre-define
* any params here. However, one must define the "oauth_token" param
* by passing a callback.
*
* ```ts
* client.getRedirectUrl((request) => {
* request.param('oauth_token', value)
* })
* ```
*/
getRedirectUrl(callback?: (request: RedirectRequestContract) => void): string | Promise<string>;
/**
* Get the access token from the oauth_verifier code. One must define
* the "oauth_verifier" code using the callback input.
*
* ```ts
* client.getAccessToken({ token, secret }, (request) => {
* request.oauth1Param('oauth_verifier', verifierValue)
* })
* ```
*/
getAccessToken(requestToken: Oauth1RequestToken, callback?: (request: ApiRequestContract) => void): Promise<Token>;
}