@oa2/core
Version:
A comprehensive, RFC-compliant OAuth 2.0 authorization server implementation in TypeScript
90 lines (87 loc) • 3.76 kB
TypeScript
import { StorageAdapter, Client, Token, AuthorizationCode } from '../types.js';
/**
* An in-memory implementation of the StorageAdapter interface for testing purposes.
* This adapter stores clients, tokens, authorization codes, and users in JavaScript Maps.
*/
declare class InMemoryStorageAdapter implements StorageAdapter {
private clients;
private tokens;
private authorizationCodes;
private users;
constructor();
getUserByCredentials(username: string, password: string): Promise<any | null>;
/**
* Retrieves a client by its ID from memory.
* @param clientId The ID of the client.
* @returns A Promise that resolves to the Client object or null if not found.
* @see RFC 6749, Section 2.2 Client Identifier
*/
getClient(clientId: string): Promise<Client | null>;
/**
* Saves a token (access token and/or refresh token) to memory.
* @param token The Token object to save.
* @returns A Promise that resolves when the token is saved.
* @see RFC 6749, Section 1.4 Access Token
* @see RFC 6749, Section 1.5 Refresh Token
*/
saveToken(token: Token): Promise<void>;
/**
* Retrieves an access token from memory.
* @param accessToken The access token string.
* @returns A Promise that resolves to the Token object or null if not found.
* @see RFC 6749, Section 1.4 Access Token
*/
getAccessToken(accessToken: string): Promise<Token | null>;
/**
* Retrieves a refresh token from memory.
* @param refreshToken The refresh token string.
* @returns A Promise that resolves to the Token object or null if not found.
* @see RFC 6749, Section 1.5 Refresh Token
*/
getRefreshToken(refreshToken: string): Promise<Token | null>;
/**
* Saves an authorization code to memory.
* @param code The AuthorizationCode object to save.
* @returns A Promise that resolves when the authorization code is saved.
* @see RFC 6749, Section 1.3.1 Authorization Code
*/
saveAuthorizationCode(code: AuthorizationCode): Promise<void>;
/**
* Retrieves an authorization code from memory.
* @param code The authorization code string.
* @returns A Promise that resolves to the AuthorizationCode object or null if not found.
* @see RFC 6749, Section 1.3.1 Authorization Code
*/
getAuthorizationCode(code: string): Promise<AuthorizationCode | null>;
/**
* Deletes an authorization code from memory.
* @param code The authorization code string to delete.
* @returns A Promise that resolves when the authorization code is deleted.
* @see RFC 6749, Section 4.1.2 Authorization Response
* "The client MUST NOT use the authorization code more than once."
*/
deleteAuthorizationCode(code: string): Promise<void>;
/**
* Revokes a token (access token or refresh token) from memory.
* @param token The token string to revoke.
* @returns A Promise that resolves when the token is revoked.
* @see RFC 7009, OAuth 2.0 Token Revocation
*/
revokeToken(token: string): Promise<void>;
/**
* Retrieves a user by their ID from memory.
* @param userId The ID of the user.
* @returns A Promise that resolves to the user object or null if not found.
* @see RFC 6749, Section 1.1 Roles (Resource Owner)
*/
getUser(userId: string): Promise<any | null>;
/**
* Saves a client to memory.
* @param client The Client object to save.
* @returns A Promise that resolves when the client is saved.
* @see RFC 6749, Section 2. Client Registration
*/
saveClient(client: Client): Promise<void>;
}
export { InMemoryStorageAdapter };
//# sourceMappingURL=index.d.ts.map