General
Requirements
...
General
Requirements
Minimum SDK Version: Android 4.4 - 4.4.4 KitKat (API level 19)
Supported U2F Authenticator Transports
...
Example U2F Sign (authenticate) code.
/** * Verifies the user's credentials and performs U2F authentication. */ public class SignInActivity extends Activity implements SurePassIdU2fSign.Listener { public static final String U2F_SERVER_URL = "https://fidocert.surepassid.com/server.aspx";
/////////////////////// // working variables // /////////////////////// private SurePassIdU2fSign mU2fSign;
private VerifyUsernamePasswordTask mVerifyUsernamePasswordTask = null;
/////////////////// // UI references // /////////////////// private EditText mUsernameView; private EditText mPasswordView; private TextView mStatusMessageView; private Button mSignInButton; /**@Override * Initiate U2F Sign. */ private protected void doU2fonCreate(Bundle savedInstanceState) { mU2fSignsuper.u2fSign(U2F_SERVER_URL, mUsernameView.getText().toString())onCreate(savedInstanceState);
} /**initUi();
* The U2F Sign was successful. Now go// toCreate the desiredU2F activity. */ @Override public void gotoTargetActivity() { Intent intent Sign object to be used.
mU2fSign = new IntentSurePassIdU2fSign(this, TargetAppActivity.class); startActivity(intentthis); } /** * TheCalled userwhen isthe requestingSign toIn usebutton anis alternate method for second factor authentication. * This alternate method is up to the relying party app. */ @Override public void gotoAlternateVerificationActivity() {pressed. */ private void doSignIn() { disableForm();
IntentString intentusername = new Intent(this, VerificationActivity.classmUsernameView.getText().toString(); startActivity(intentString password = mPasswordView.getText().toString();
} /**// Verify username an password on server. * The user aborted the sign in. */ @Override public void u2fSignCanceled mVerifyUsernamePasswordTask = new VerifyUsernamePasswordTask(new AsyncTaskListener() { displayMessage("Sign In canceled."); @Override public } void onAsyncTaskFail(String errorMessage) { /** * An error occurred during processing. * * @param errorMessage The error that occurredmPasswordView.requestFocus(); */ @Override public void u2fSignError(CharSequence errorMessage) { displayMessagemPasswordView.selectAll(errorMessage); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceStatedisplayMessage(errorMessage); initUi(); }
// Create the U2F Sign object to be used./** mU2fSign = new SurePassIdU2fSign(this, this); } /** * Call the U2F Sign's onActivityResult method. * @param requestCode * @param resultCode * @param intent */ @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { * Called when the username and password have successfully validated. * It then calls U2F Sign. */
@Override public void onAsyncTaskSuccess() { mU2fSignLog.onActivityResultv(requestCodeTAG, resultCode, intent"onAsyncTaskSuccess([]): START"); } /** * Initialize the user interface. */ private void initUi() { doU2f(); } mStatusMessageView = (TextView) findViewById(R.id.status_message }); mUsernameView = (EditText) findViewById(R.id.usernamemVerifyUsernamePasswordTask.execute(username, password); } mPasswordView = (EditText) findViewById(R.id.password); mSignInButton = (Button) findViewById(R.id.button_sign_in/** * Initiate U2F Sign. */ private void doU2f() { mU2fSign.u2fSign(U2F_SERVER_URL, mUsernameView.getText().toString()); }
/** * The U2F Sign was successful. Now go to the desired activity. */ @Override public void gotoTargetActivity() { Intent intent = new Intent(this, TargetAppActivity.class); mSignInButton.setOnClickListener(new View.OnClickListener() {startActivity(intent); }
/** * The user is requesting to use an @Override alternate publicmethod voidfor onClick(View view) {second factor authentication. * This alternate method is up to the relying party app. */ @Override public void doSignIngotoAlternateVerificationActivity(); { Intent intent = }new Intent(this, VerificationActivity.class); }startActivity(intent); }
/** * CalledThe user whenaborted the Sign In button is pressedsign in. */ private@Override public void doSignInu2fSignCanceled() { displayMessage("Sign In canceled."); disableForm();}
/** * An error Stringoccurred username = mUsernameView.getText().toString();during processing. * * @param errorMessage The error Stringthat password = mPasswordView.getText().toString(); // Verify username an password on server.occurred. */ @Override public void u2fSignError(CharSequence errorMessage) { displayMessage(errorMessage); }
mVerifyUsernamePasswordTask = new VerifyUsernamePasswordTask(new AsyncTaskListener() { @Override public void onAsyncTaskFail(String errorMessage) { /** * Call the U2F Sign's onActivityResult method. * @param requestCode * @param resultCode * @param intent */ @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { mPasswordViewmU2fSign.requestFocus(onActivityResult(requestCode, resultCode, intent); }
/** * Initialize the user mPasswordView.selectAll();interface. */ private void initUi() { mStatusMessageView = displayMessage(errorMessage(TextView) findViewById(R.id.status_message); mUsernameView = }(EditText) findViewById(R.id.username); mPasswordView = (EditText) /** * Called when the username and password have successfully validated. * It then calls U2F Sign. */ @Override public void onAsyncTaskSuccessfindViewById(R.id.password);
mSignInButton = (Button) findViewById(R.id.button_sign_in); mSignInButton.setOnClickListener(new View.OnClickListener() { @Override public void Log.v(TAG, "onAsyncTaskSuccess([]): START");onClick(View view) { doU2fdoSignIn(); } }); mVerifyUsernamePasswordTask.execute(username, password); }
protected void displayMessage(CharSequence message) { mStatusMessageView.setText(message); } }
|
---|