svoauth
Version:
`svoauth` is a minimal and flexible OAuth 2.0 wrapper designed for SvelteKit projects. It uses a config-driven approach so you can easily plug in providers like GitHub, Google, and more.
115 lines (112 loc) • 2.43 kB
TypeScript
import { RequestEvent } from "@sveltejs/kit";
//#region \0dts:/home/runner/work/svoauth/svoauth/src/types/index.d.ts
type Scopes = {
values: string[]
delimiter?: " " | "," | ":"
};
interface OAuthClient {
clientId: string;
clientSecret: string;
authorizeUrl: string;
tokenUrl: string;
revokeTokenUrl?: string;
refreshTokenUrl?: string;
redirectUri: string;
pkce?: boolean;
basicAuth?: boolean;
scopes: Scopes;
params?: Record<string, string>[];
}
interface Tokens {
hasAccessToken(): boolean;
hasRefreshToken(): boolean;
accessToken(): string;
refreshToken(): string;
expiresAt(): Date | undefined;
refreshToken(): string;
idToken(): string;
}
type OAuthConfigs = Record<string, OAuthClient>;
//#endregion
//#region \0dts:/home/runner/work/svoauth/svoauth/src/index.d.ts
/**
* Single instance of a client
*
* @export
* @class OAuthInstance
* @typedef {OAuthInstance}
*/
/**
* Single instance of a client
*
* @export
* @class OAuthInstance
* @typedef {OAuthInstance}
*/
declare class OAuthInstance {
#private;
/**
* Creates an instance of OAuthInstance.
*
* @constructor
* @param {OAuthClient} client
*/
constructor(client: OAuthClient);
/**
* Generates an authorize url for the client config
*
* @param {RequestEvent} event
* @returns {string}
*/
generateAuthorizeUrl(event: RequestEvent): string;
/**
* Takes your callback request and gives you a TokenResponse
*
* @async
* @param {RequestEvent} event
* @returns {Promise<Tokens>}
*/
exchangeCodeForToken(event: RequestEvent): Promise<Tokens>;
/**
* Use your refresh token to get a new access token
*
* @async
* @param {string} refreshToken
* @returns {Promise<Tokens>}
*/
refreshToken(refreshToken: string): Promise<Tokens | null>;
/**
* Use your access token or refresh token to revoke access.
*
* @async
* @param {string} token
* @returns {Promise<TokenResponse>}
*/
revokeToken(token: string): Promise<boolean>;
}
/**
* Global handler to access all your clients config
*
* @export
* @class OAuthHandler
* @typedef {OAuthHandler}
*/
declare class OAuthHandler {
#private;
/**
* Creates an instance of OAuthHandler.
*
* @constructor
* @param {OAuthConfigs} clients
*/
constructor(clients: OAuthConfigs);
/**
* Get an OAuthInstance by name (github, google, etc)
*
* @param {string} clientName
* @returns {OAuthInstance}
*/
get(clientName: string): OAuthInstance;
}
//#endregion
export { OAuthHandler };