forgerock-android-onboarding

Installation

  1. Added the ForgeRock dependency
dependencies {
    implementation 'org.forgerock:forgerock-auth:3.1.2'
}
  1. Add Android configuration for ForgeRock SDK in strings.xml
 <!-- OAuth 2.0 Client Details -->
    <string name="forgerock_oauth_client_id" translatable="false">jeyonboarding</string>
    <string name="forgerock_oauth_redirect_uri" translatable="false">com.forgerock.android:/oauth2redirect</string>
    <string name="forgerock_oauth_scope" translatable="false">openid profile email address phone</string>
    <integer name="forgerock_oauth_threshold" translatable="false">30</integer>
    <!-- AM Instance Details -->
    <string name="forgerock_url" translatable="false">https://openam-forgerrock-sdks.forgeblocks.com/am</string>
    <string name="forgerock_cookie_name" translatable="false">iPlanetDirectoryPro</string>
    <string name="forgerock_realm" translatable="false">alpha</string>
    <integer name="forgerock_timeout" translatable="false">30</integer>
    <!-- Single Sign-On Details -->
    <string name="forgerock">ForgeRock SDK Tutorial</string>
    <string name="forgerock_account_name" translatable="false">Demo User</string>
    <!-- AM Tree Details -->
    <string name="forgerock_auth_service" translatable="false">jeySdkAuthenticationTree</string>
  1. Created the Application class and start the Forgerock authentication
   FRAuth.start(this)

Embedded Login

  1. create a MainActivity class and have a login, status and logout button
  2. Add Forgerock Login , Logout Listener for the buttons
  3. Create a Dialog Fragment with username, password, cancel, next button
  4. On click of Login button, Invoke the DialogFragment from success of Journey/tree callback to display username/password dialog
  5. Add the Listener for the next button on the Dialog fragment which will take the input from username and password field and execute the three step login process
    1. You will receive a SSO token or tokenId from the authentication journey/tree response
    2. Use that SSO token to fetch the redirect URI and authcode
    3. Exchange the authcode to get and oauth tokens and this is the Final step
  6. update the Login logout status in Main activity once you received the access token, refresh token , idToken
  7. Get the User Info in a different Fragment screen

Centralized Login

  1. create a build variant to run two different product flavours in build.gradle, so that you can use the same code to run centralized and embedded login
  2. Add the URI scheme for the app for centralize login
  3. Add the openId auth dependency
dependencies {
    implementation 'net.openid:appauth:0.7.1'
    }
  1. make sure your gradle properties has
android.useAndroidX=true
android.enableJetifier=true
  1. Add queries and RedirectUriReceiverActivity to open the login in browser
  2. on click of login button now invoke the FRUser.browser().appAuthConfigurer()
  3. This will open a Login page in separate browser page to Enter username and password credentials
  4. OnSuccesful Authentication fetch all the oauth tokens