Skip to content

Commit

Permalink
Merge pull request #149 from Onegini/EXAMPLEAND-60
Browse files Browse the repository at this point in the history
EXAMPLEAND-60 example single sign-on implementation
  • Loading branch information
Robert Szuba authored May 29, 2019
2 parents 753591b + 523ce85 commit bb4e99f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.onegini.mobile.exampleapp.view.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -36,9 +37,11 @@
import com.onegini.mobile.sdk.android.handlers.OneginiDeregisterUserProfileHandler;
import com.onegini.mobile.sdk.android.handlers.OneginiLogoutHandler;
import com.onegini.mobile.sdk.android.handlers.OneginiMobileAuthWithOtpHandler;
import com.onegini.mobile.sdk.android.handlers.OneginiSingleSignOnHandler;
import com.onegini.mobile.sdk.android.handlers.error.OneginiDeregistrationError;
import com.onegini.mobile.sdk.android.handlers.error.OneginiLogoutError;
import com.onegini.mobile.sdk.android.handlers.error.OneginiMobileAuthWithOtpError;
import com.onegini.mobile.sdk.android.handlers.error.OneginiSingleSignOnError;
import com.onegini.mobile.sdk.android.model.entity.UserProfile;

public class DashboardActivity extends AppCompatActivity {
Expand Down Expand Up @@ -187,6 +190,34 @@ public void startSettingsActivity() {
startActivity(new Intent(this, SettingsActivity.class));
}

@SuppressWarnings("unused")
@OnClick(R.id.button_single_sign_on)
public void startSingleSignOn() {
final Uri targetUri = Uri.parse("https://demo-cim.onegini.com/personal/dashboard");

final OneginiClient oneginiClient = OneginiSDK.getOneginiClient(this);
oneginiClient.getUserClient().getSingleSignOnUri(targetUri, new OneginiSingleSignOnHandler() {
@Override
public void onSuccess(final Uri uri) {
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}

@Override
public void onError(final OneginiSingleSignOnError oneginiSingleSignOnError) {
@OneginiSingleSignOnError.SingleSignOnErrorType int errorType = oneginiSingleSignOnError.getErrorType();
if (errorType == OneginiDeregistrationError.DEVICE_DEREGISTERED) {
// Deregistration failed due to missing device credentials. Register app once again.
new DeregistrationUtil(DashboardActivity.this).onDeviceDeregistered();
}

// other errors don't really require our reaction, but you might consider displaying some message to the user
showToast("Single Sign-On error: " + oneginiSingleSignOnError.getMessage());
}
});
}

private void showToast(final String message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/layout/activity_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
android:id="@+id/button_auth_with_otp"
style="@style/ButtonStyle"
android:text="@string/btn_mobile_auth_with_otp_label"/>
<Button
android:id="@+id/button_single_sign_on"
style="@style/ButtonStyle"
android:text="@string/btn_single_sign_on_label"/>
<Button
android:id="@+id/button_settings"
style="@style/ButtonStyle"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<string name="simple_push_message">Simple push message</string>
<string name="change_pin_finished_successfully">Change PIN action finished successfully</string>
<string name="btn_mobile_auth_with_otp_label">Mobile auth with OTP</string>
<string name="btn_single_sign_on_label">Single Sign-On</string>
<string name="btn_cancel_label">CANCEL</string>
<string name="btn_ok_label">OK</string>
<string name="push_token_is_null_error_message">The push token is null, check if your Firebase configuration in google-services.json file is valid.</string>
Expand Down

0 comments on commit bb4e99f

Please sign in to comment.