1.4.2 • Published 5 months ago

@carisls/keycloak-client v1.4.2

Weekly downloads
51
License
-
Repository
gitlab
Last release
5 months ago

Instructions

NPM Version NPM Downloads Install Size Pipeline

An integration client for Keycloak for Caris applications.

Installation

npm i @carisls/keycloak-client

Middleware

Adding of basic piece to handle user injection and redirections to retrieve user.

const keycloakClient = require('@carisls/keycloak-client');
app.use(keycloakClient.router({
  clientId: 'my-client'
  ssoUrl: process.env.SSO_URL,
  encPassword: process.env.ENC_PASSWORD
}));
OptionAPI RouterDescription
ssoUrlANYUrl to use as SSO server base url
clientIdANYClient Id
clientSecretANYClient Secret (if enabled)
apiN/AIf API Router we need to set this setting to true to prevent any redirections
standardN/AWhether to use implicit (default) or a standard flow
useCachedSessionN/AWhether to use token caching (in case of large tokens)
publicKeyANYOverriding a default public certificate (provided by SSO Server)
publicKeyCacheANYTime in seconds when a fetched publicKey should expire
encPasswordANYSetting encryption password for session cookie
encPasswordSaltANYSetting encryption password salt for session cookie
encIterationCountANYSetting encryption password number of hash iterations for session cookie
paths.loginfalseOverriding a default /login path to initiate login
paths.ssofalseOverriding a default /sso path to receive user token
paths.logoutfalseOverriding a default /logout path to initiate logout
paths.afterLoginfalseOverrides a default / path where to send user after a successful login
paths.afterLogoutfalseOverrides a default / path where to send user after a successful logout
expOffsetfalseWhen x-session cookie will expire (in seconds). Negative is earlier, positive later. Default is 0

NOTE: You can include publicKey option or not. If not, client will get it by following OpenID standard (.well-known).

NOTE: If it is API, we do not have "sending user to login" so we need to pass api: true to options.

Authorization

Adding middleware to authorize requests.

const authorize = keycloakClient.authorize;
app.use(authorize('my-app-role', [
  '/403.html',
  '/assets'
]));

Middleware authorize has three parameters:

NoParameter NameRequiredDefaultDescription
1rolesfalsenullNeeded roles to pass or null for all authenticated (one role string or array of strings)
2exceptionsfalse[]What paths to exclude. Matches exact url and from the start (/peter will match both /peter and /peterson and /peter/some-file.txt)
3redirectToLoginfalsetrueIf not set as false it will redirect user to /login?ReturnUrl={encodedUrl}. If set to false it will throw 401

Client Enpoints

Base Url for a realm:

https://{domain}/auth/realms/{realm}

Paths:

  • POST /protocol/openid-connect/token (ValidateCredentials)

Base Url for a realm admin:

https://{domain}/auth/admin/realms/{realm}

Paths:

  • GET /users?email=something@carisls.com (FindAUserByEmail)
  • DELETE /users/{user.id} (DeleteUser)
  • POST /users (CreateUser)
  • PUT /users/{user.id}/reset-password (UpdateUser)

Base Url for the master realm:

https://{domain}/auth/realms/master

Paths:

  • POST /protocol/openid-connect/token (GetAdminToken)
1.4.2

5 months ago

1.4.1

6 months ago

1.4.0

6 months ago

1.3.6

11 months ago

1.3.5

11 months ago

1.3.4

12 months ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

2 years ago

1.2.0

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.3

2 years ago

0.9.13

2 years ago

0.9.12

3 years ago

0.9.9

3 years ago

0.9.10

3 years ago

0.9.11

3 years ago

0.9.8

3 years ago

0.9.7

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.0

3 years ago

0.8.7

3 years ago

0.8.6

3 years ago

0.8.5

3 years ago

0.8.4

3 years ago

0.8.3

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.4

3 years ago

0.8.2

3 years ago

0.7.3

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago