- TypeScript support
- ESModule support
- Working with React, Angular and other popular front-end libraries
- Logging user in using redirect to the auth service
- Getting user info claims
- Supplying access token for requests to the back-end
- Automatic refreshing of the access token with refresh token when it expires
- Logging user out from the application and from the auth service
npm install auth-oidc --save
import {AuthService} from 'auth-oidc'
new AuthService(config)
Config object fields:
- authority: URL to the authentication service (f.e. http://[host]/realms/[realm-name])
- clientId: ID of the application registered within authentication service
- (OPTIONAL) errorHandler: callback function that will be called in case of auth errors
- Defaults to (error) => console.log(error)
- (OPTIONAL) autoLogin: Determines whether authentication should start automatically when page loaded
- Defaults to false
Login will be started automatically if it was configured to do so, if no, you can start it by
authService.login()
You can also specify a URL the user will be returned to:
authService.login('http://loclahost:3000')
You can check login status with
authService.isLoggedIn()
To get user info claim you can use
authService.getUserInfo('name')
You can get user access token with
authService.getToken()
You can force lib to refresh tokens and user info with:
authService.tryToRefresh()
You can log out user from your application and authentication service with
authService.logout()
You can also specify a URL the user will be returned to:
authService.logout('http://loclahost:3000')
Released under the MIT License. See the LICENSE file.