Keycloak on Sunbird

Introduction

High level architecture depicting the components connected to Keycloak

  • Only a handful of services connect to Keycloak

  • Only nginx public has been allowed and configured to connect to keycloak is the traffic originates from outside VPC

  • Portal, learner service and Vidydaan system connect to Keycloak via nginx public using the domain name

  • Keycloak connects to learner service via nginx private ingress

Provision, bootstrap , build, configuration and deploy instructions

Custom changes done by Sunbird

Realm Settings and configurations

Federation setup with Cassandra

  • This comes already pre installed as per the the realm setup when you run Deploy/Kubernetes/KeycloakRealm jenkins job

  • The federation provider is used to connect to learner service and fetch the user data from cassandra

  • For more details on federation and code, reach out to https://github.com/Sunbird-Lern community

Login, Signup, Forgot password flows

  • These are standard workflows similar to any website

  • You can use phone number / email to signup or login or reset password

  • All these flows use the SPI code and connect to learner service

  • Signup flow connects to learner service and creates the user in cassandra and sets the password on keycloak database

  • Login flow connects to learner service and fetches the user data from cassandra and validates the password from keycloak database

  • For password flow connects to learner service and fetches the user data from cassandra and resets the password on keycloak database

  • For more details on these flows and intricate details of API and code functionality, reach out to https://github.com/Sunbird-Lern community

User sessions

  • User sessions are stored in keycloak hep memory

  • The sessions can be viewed on the keycloak admin page under users page or on the client page

  • Sessions get auto expired on logout or on validity end time

  • The access token validity configuration for the realm decides the validity end time

Operations and Maintenance

Scaling up

Scaling down

Upgrade

Known issues

  • There are no known issues with respect to Keycloak after the package was upgraded to 7.0.1

 

 

Sunbird Auth Architecture

Current Authentication Architecture

Attached are some diagrams that depict the current authentication architecture

Email/Phone number based sign up and sign in

 

Google based sign in

 

State sso sign in

 

Mobile refresh token workflow

  1. The portal does not use the refresh tokens to get new access tokens.

  2. The mobile app saves the refresh token and uses it to get a new access token once the existing access token expires

  3. The app leverages the same portal flows above, but has a URL parameter indicating that is mobile. The workflows above (implemented on portal) route to a mobile specific url at the end of the process. The mobile app listens on these specific URLs and gets access to the refresh and access token as mentioned below.
    - In email/phone sign in, the app gets redirected to /oauth2callback?code={code}. It invokes a keycloak endpoint (/auth/realms/sunbird/protocol/openid-connect/token) to exchange the code to get the tokens
    - In the state SSO sign in, the app gets redirected to /sso/sign-in/success?id={id}. It invokes a portal endpoint (/v1/sso/create/session?id={extracted[‘id’]}) to exchange the ID to get the tokens
    - In the google sign in workflow, the app gets the tokens directly as query params

 

     Â