HTML5/JS

This document describes how to integrate Galaxy ID for HTML5/JavaScript applications.

Software Name: Galaxy ID

Software Version: 0.1

Acronyms and Terms

No.

Words

Descriptions

1

GID

Galaxy ID

2

SSO

Single Sign-On

4

Client

An application that integrates for GID

Summary

Galaxy ID is an SSO system. It provides endpoints that enable clients to authenticate and authorize in many places.

Prepare

We will use a Javascript library, kecloak-js to integrate Galaxy ID. It can be installed via:

Or you can also use keycloak.js directly.

Integrate

Initialize keycloak

Place the keycloak.json file (supplied) in the same location as the HTML page and initialize:

Or you can also specify the keycloak.json file somewhere else:

By default, for authentication, we need to call login. However, there are two options to automate the authentication work:

  • login-required: It will authenticate if logged in or display the login page if not authenticated.

  • check-sso: It will only authenticate if the user is logged in. If the user is not logged in, it will redirect back to the application.

To use, pass onLoad to the keycloak.init () function.

We can also use check-sso silently without redirecting to the server and vice versa, but through a hidden iframe:

Token

After successful authentication, we can get Bearer token from keycloak.token

Since the lifetime of the access token is short, we need to update the new token by calling the updateToken method.

Get user information

The user's information can be obtained from the returned token of the GID (recommended because it reduces the load of a significant request on the server) by calling keycloak.token parsed token parsed

Or it can also be done through the Restful API in the next section.

APIs

Get user information

URL: <host>/realms/<realmName>/protocol/openid-connect/userinfo

Method: GET

Header: Authorization: Bearer <access token> (keycloak)

Example request:

Example response:

Logout with API

URL: <host>/realms/<realmName>/protocol/openid-connect/logout

Method: GET

Header: Authorization: Bearer <access token> (keycloak)

Example request:

Example response:

  • Status: 204 (No Content)

keycloak-documentation/javascript-adapter.adoc at main · keycloak/keycloak-documentation (github.com)

Last updated