simple-oauth2-ts-client
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "simple-oauth2-ts-client", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A TypeScript OAuth 2.0 client library", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,1 +0,87 @@ | ||
# oauth_client | ||
# OAuth 2.0 Client Library Implementation | ||
So for the Implementation of the Library, i have followed the specs proposed by IETF OAuth Working Group. | ||
So Basic flow of the protocol: | ||
## OAuth2.0 Abstract Flow | ||
![Diagram](https://github.com/user-attachments/assets/014f5341-5c34-49f5-b98e-67c65fcc950e) | ||
## Features | ||
It is a light weight package only has `axios ` as its dependencies, uses `web crypto` which are built-in since Node 18 (but it works with Polyfills on Node 14 and 16). | ||
It is platform agnostic which can be used in both client and server javascript environment . | ||
Following OAuth Grant, it Supports | ||
- Authorization Code | ||
- PKCE | ||
- Client Credentials | ||
- Refresh Token | ||
- Legacy: Implicit Flow | ||
## Installation | ||
Install simple-oauth2-ts-client | ||
with npm | ||
```bash | ||
npm i simple-oauth2-ts-client | ||
``` | ||
## Usage/Examples | ||
To get started with initialize the client with the following attributes | ||
```javascript | ||
const client =new OAuthClient({ | ||
auth_server: string; //authorisation server domain endpoint | ||
client_id: string; // provided by auth server for public client | ||
client_secret?: string; // provided by auth server for confidential client | ||
redirect_uri: string; // redirection uri for Authorization Code && implicit grant type | ||
authorization_endpoint?: string; // @default /authorize | ||
token_endpoint?: string; // @default /token | ||
authenticationMethod?: "client_secret_basic" | "client_secret_post" | "none"; | ||
}) | ||
``` | ||
This client Object has following method to use for various purposes | ||
```javascript | ||
// This will return redirection uri --> | ||
await client.startAuthFlow( | ||
params: OAuthStartAuthFlow | ||
): Promise<OAuthStartAuthFlowResponse> // can be used for Authorization Code or implicit grants | ||
// to handle successful redirection uri | ||
await client.handleCallback(params: { | ||
uri: string; // redirection back uri | ||
grant_type: OAuth2GrantType; // use authorization_code for Authorization Code grant type | ||
state?: string; // // Optional string that can be sent along to the auth server. This value will | ||
// be sent along with the redirect back to the app verbatim. | ||
code_verifier?: string; // to support PKCE | ||
}): Promise<OAuth2Token> | ||
// to handle refresh token | ||
await client.refreshToken( | ||
refreshToken: string, | ||
params?: RefreshParams | ||
): Promise<OAuth2Token> | ||
``` | ||
To generate code verifier and codeChallenge , it exports uility function to do This | ||
`await generateCodeVerifier(): Promise<string>` | ||
36444
88