Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/misha999777/auth-oidc
Small JS lib for OpenID Connect authentication.
https://github.com/misha999777/auth-oidc
javascript npmjs openid
Last synced: 3 months ago
JSON representation
Small JS lib for OpenID Connect authentication.
- Host: GitHub
- URL: https://github.com/misha999777/auth-oidc
- Owner: Misha999777
- License: mit
- Created: 2021-08-07T19:05:37.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-06-28T08:36:33.000Z (6 months ago)
- Last Synced: 2024-10-13T01:21:04.324Z (3 months ago)
- Topics: javascript, npmjs, openid
- Language: JavaScript
- Homepage:
- Size: 161 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Authenticate users with OpenID Connect authentication service (f.e. Keycloak)
[![License](https://img.shields.io/:license-MIT-green.svg)](https://github.com/Misha999777/auth-oidc/blob/master/LICENSE)## Main features:
1. TypeScript support
2. ESModule support
3. Working with React, Angular and other popular front-end libraries
4. Logging user in using redirect to the auth service
5. Getting user info claims
6. Supplying access token for requests to the back-end
7. Automatic refreshing of the access token with refresh token when it expires
8. Logging user out from the application and from the auth service## How to use
### 1. Install library using npmnpm install auth-oidc --save### 2. Import AuthService
import {AuthService} from 'auth-oidc'### 3. Initialize AuthService
new AuthService(config)Config object fields:
1. **authority**: URL to the authentication service (f.e. http://[host]/realms/[realm-name])
2. **clientId**: ID of the application registered within authentication service
3. (OPTIONAL) **autoLogin**: whether authentication should start automatically on page load
* Defaults to false
4. (OPTIONAL) **callbackUrl**: a URL the user will be returned to after completing login/logout
* Defaults to window.location.href
5. (OPTIONAL) **errorHandler**: callback function that will be called in case of auth errors
* Defaults to (error) => console.log(error)### 4. Start login
Login will be started automatically if it was configured to do so, if no, you can start
it byauthService.login()
You can also override a URL the user will be returned to after login:authService.login('http://loclahost:3000/page')### 5. Check login status
You can check login status withauthService.isLoggedIn()### 6. Get user info claims
To get user info claim you can useauthService.getUserInfo('name')### 7. Get access token to make requests
You can get user access token withauthService.getToken()### 8. Force refresh
You can force lib to refresh tokens and user info with:authService.tryToRefresh()### 9. Logout user
You can log out user from your application and authentication service withauthService.logout()
You can also override a URL the user will be returned to after logout:authService.logout('http://loclahost:3000/page')## Copyright
Released under the MIT License.
See the [LICENSE](https://github.com/Misha999777/auth-oidc/blob/master/LICENSE) file.