Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sachin-chaurasiya/sso-clients
A TypeScript supported package for SSO login.
https://github.com/sachin-chaurasiya/sso-clients
github google oauth oauth2 oauth2-client sso-client sso-clients
Last synced: 9 days ago
JSON representation
A TypeScript supported package for SSO login.
- Host: GitHub
- URL: https://github.com/sachin-chaurasiya/sso-clients
- Owner: Sachin-chaurasiya
- License: mit
- Created: 2023-07-22T08:31:30.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-16T05:08:08.000Z (10 months ago)
- Last Synced: 2024-10-11T13:17:51.698Z (26 days ago)
- Topics: github, google, oauth, oauth2, oauth2-client, sso-client, sso-clients
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/sso-clients
- Size: 164 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: license
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# SSO Clients
## Clients
- [Google](#import-the-google-client)
- [GitHub](#import-the-github-client)
- [Auth0](#import-the-auth0-client)## Installation
```bash
npm install sso-clientsOR
yarn add sso-clients
```
## Usage### Import the Google Client
```js
import { GoogleOAuth2 } from "sso-clients";
```### Initialize the Client
```js
const googleOAuth = new GoogleOAuth2(
"YOUR_GOOGLE_CLIENT_ID",
"YOUR_GOOGLE_CLIENT_SECRET",
"YOUR_CALLBACK_URL",
["email", "profile", "openid"],
);```
### Import the GitHub Client
```js
import { GithubOAuth2 } from "sso-clients";
```### Initialize the Client
```js
const githubOAuth = new GithubOAuth2(
"YOUR_GITHUB_CLIENT_ID",
"YOUR_GITHUB_CLIENT_SECRET",
"YOUR_CALLBACK_URL",
['user:email']
);```
### Import the Auth0 Client
```js
import { Auth0OAuth2 } from "sso-clients";
```
### Initialize the Client```js
const auth0OAuth = new Auth0OAuth2(
"YOUR_AUTH0_CLIENT_ID",
"YOUR_AUTH0_CLIENT_SECRET",
"YOUR_CALLBACK_URL",
"YOUR_AUTH0_DOMAIN",
["openid", "profile", "email", "offline_access"],
);```
## Available methods for a client
- `getName(): string`: Returns the name of the provider.
- `getLoginURL(): string`: Returns the URL for provider login.
- `getTokens(code: string): Promise`: Exchanges the authorization code for the access token. Returns a Promise that resolves to the tokens (access token, token type, expires in, and optional refresh token).
- `refreshTokens(refreshToken: string): Promise`: Refreshes the access token using the provided refresh token. Returns a Promise that resolves to the updated tokens.
- `getUserID(accessToken: string): Promise`: Fetches the user ID using the provided access token.
- `getUserEmail(accessToken: string): Promise`: Retrieves the user's email using the access token. Returns a Promise that resolves to the user's email.
- `isEmailVerified(accessToken: string): Promise`: Checks if the user's email is verified using the access token. Returns a Promise that resolves to a boolean indicating email verification status.
- `getUserName(accessToken: string): Promise`: Retrieves the user's name using the access token. Returns a Promise that resolves to the user's name.
- `getUser(accessToken: string): Promise`: Retrieves the user's information (sub, email, email_verified, name) using the access token. Returns a Promise that resolves to the user object.