0.0.8 • Published 1 year ago
@asciijr/keycloak v0.0.8
library @asciijr/keycloak
Installation
yarn add @asciijr/keycloak
Usage
set this variables in your environment with your keycloak configuration
KEYCLOAK_REALM='master'
KEYCLOAK_CLIENT_ID='example'
KEYCLOAK_CLIENT_SECRET='your client secret'
KEYCLOAK_URL='http://localhost:8081/auth'
KEYCLOAK_ADMIN_LOGIN='admin'
KEYCLOAK_ADMIN_PASSWORD='admin'
import { Keycloak } from '@asciiej/keycloak';
/** login
* returns: {accessToken: string, refreshToken: string}
*/
Keycloak.loginUser({
username: 'johndoe',
password: '123456'
});
/** get user
* returns: {id: string, username: string}
*/
Keycloak.getUser({
accessToken: 'provide the accessToken'
});
/** create user
* returns: { id: string }
*/
Keycloak.createUser({
email: "johndoe1@example.com",
username: "johndoe1",
firstName: "John",
lastName: "Doe",
password: "123456",
attributes?: {
customAttribute: any
}
});
/** logout
* returns: boolean
*/
Keycloak.logoutUser({
accessToken: 'provide the accessToken',
refreshToken: 'provide the refreshToken',
});
/** refresh
* returns: {accessToken: string, refreshToken: string}
*/
Keycloak.refreshLogin({
refreshToken: 'provide the refreshToken',
});