General
Requirements
Minimum SDK Version: Android 4.4 - 4.4.4 KitKat (API level 19)
Supported U2F Authenticator Transports
- NFC (requires
- USB HID
- Bluetooth Low Energy (A.K.A. BLE, Bluetooth Smart)
- Virtual (included in client)
Example U2F Sign (authenticate) code.
...
General
Requirements
Minimum SDK Version: Android 4.4 - 4.4.4 KitKat (API level 19)
Supported U2F Authenticator Transports
- NFC (requires
- USB HID
- Bluetooth Low Energy (A.K.A. BLE, Bluetooth Smart)
- Virtual (included in client)
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;
/** * Initiate U2F Sign. */ private void doU2f() { displayMessage("Sign In canceled."mU2fSign.u2fSign(U2F_SERVER_URL, mUsernameView.getText().toString()); }
/** * AnThe errorU2F occurredSign duringwas processingsuccessful. *Now go * @param errorMessage The error that occurredto the desired activity. */ @Override public void u2fSignErrorgotoTargetActivity(CharSequence errorMessage) { displayMessage(errorMessageIntent intent = new Intent(this, DemoAppActivity.class); enableFormstartActivity(intent); }
@Override/** * protectedThe voiduser onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initUi(); // Create the U2F Sign object to be used. mU2fSignis requesting to use an alternate method for second factor authentication. * This alternate method is up to the relying party app. */ @Override public void gotoAlternateVerificationActivity() { Intent intent = new SurePassIdU2fSignIntent(this, thisDemoCodeActivity.class); } /**startActivity(intent); * Call the U2F}
Sign's onActivityResult method. /** @param requestCode * The @paramuser resultCode aborted *the @paramsign intentin. */ @Override public void onActivityResult(int requestCode, int resultCode, Intent intentu2fSignCanceled() { mU2fSign.onActivityResult(requestCode, resultCode, intentdisplayMessage("Sign In canceled."); }
/** * Initialize the user interfaceAn error occurred during processing. * * @param errorMessage The error that occurred. */ private@Override public void initUiu2fSignError(CharSequence errorMessage) { mStatusMessageView = (TextView) findViewById(R.id.status_messagedisplayMessage(errorMessage); }
@Override mUsernameView protected =void onCreate(EditTextBundle savedInstanceState) findViewById(R.id.username{ super.onCreate(savedInstanceState); mPasswordView = (EditText) findViewByIdinitUi(R.id.password);
mSignInButton// =Create (Button) findViewById(R.id.button_sign_in); mSignInButton.setOnClickListener(new View.OnClickListener() {the U2F Sign object to be used. mU2fSign = new SurePassIdU2fSign(this, this); @Override public void onClick(View view) { doSignIn(); } }
/** * Call the U2F Sign's onActivityResult method. * @param requestCode * @param resultCode * @param intent */ @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { mU2fSign.onActivityResult(requestCode, resultCode, }intent); }
/** * CalledInitialize when the Sign In button is presseduser interface. */ private void doSignIninitUi() { disableForm(mStatusMessageView = (TextView) findViewById(R.id.status_message); String usernamemUsernameView = mUsernameView.getText(EditText).toString( findViewById(R.id.username); StringmPasswordView password = mPasswordView.getText(EditText).toString( findViewById(R.id.password);
// Verify username an passwordmSignInButton on server. displayMessage= (Button) findViewById(R.stringid.signinbutton_statussign_signing_in); mVerifyUsernamePasswordTask = new VerifyUsernamePasswordTaskmSignInButton.setOnClickListener(new AsyncTaskListenerView.OnClickListener() { @Override public void onAsyncTaskFailonClick(StringView errorMessageview) { mPasswordView.requestFocusdoSignIn(); mPasswordView.selectAll();} }); }
enableForm(); displayMessage(errorMessage);/** * Called when the Sign In button is pressed. */ private void doSignIn() { disableForm();
} String username = mUsernameView.getText().toString(); /** * Called when the username and String password have successfully validated. * It then calls U2F Sign. */ @Override public void onAsyncTaskSuccess() {= mPasswordView.getText().toString();
// Verify username an password on server. mVerifyUsernamePasswordTask = Log.v(TAG, "onAsyncTaskSuccess([]): START");new VerifyUsernamePasswordTask(new AsyncTaskListener() { @Override public void onAsyncTaskFail(String doU2f(errorMessage); { }mPasswordView.requestFocus(); }); mVerifyUsernamePasswordTaskmPasswordView.executeselectAll(username, password); } protected void displayMessage(int messageId) { mStatusMessageView.setTextdisplayMessage(messageIderrorMessage); } protected void displayMessage(CharSequence message) {}
mStatusMessageView.setText(message); } protected void resetFormValues() { mUsernameView.requestFocus(); mUsernameView.setText(""); mPasswordView.setText("");/** * Called when the username and password have successfully validated. * It then calls U2F Sign. */ @Override public void onAsyncTaskSuccess() { mStatusMessageView.setText(""); } private void disableForm() { Log.v(TAG, "onAsyncTaskSuccess([]): START"); mUsernameView.setEnabled(false); mPasswordView.setEnableddoU2f(false); mSignInButton.setVisibility(GONE); } protected void enableForm(}) {; mUsernameViewmVerifyUsernamePasswordTask.setEnabled(trueexecute(username, password); }
mPasswordView.setEnabled(true);protected void displayMessage(CharSequence message) { mSignInButtonmStatusMessageView.setVisibilitysetText(VISIBLEmessage); } } |
---|