Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »


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() {
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, DemoAppActivity.class);
startActivity(intent);
}

/**
* The user is 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 Intent(this, DemoCodeActivity.class);
startActivity(intent);
}

/**
* The user aborted the sign in.
*/
 @Override
 public void u2fSignCanceled() {
displayMessage("Sign In canceled.");
}

/**
* An error occurred during processing.
*
* @param errorMessage The error that occurred.
*/
 @Override
 public void u2fSignError(CharSequence errorMessage) {
displayMessage(errorMessage);
}

@Override
 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

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) {
mU2fSign.onActivityResult(requestCode, resultCode, intent);
}

/**
* Initialize the user interface.
*/
 private void initUi() {
mStatusMessageView = (TextView) findViewById(R.id.status_message);
mUsernameView = (EditText) findViewById(R.id.username);
mPasswordView = (EditText) findViewById(R.id.password);

mSignInButton = (Button) findViewById(R.id.button_sign_in);
mSignInButton.setOnClickListener(new View.OnClickListener() {
@Override
 public void onClick(View view) {
doSignIn();
}
});
}

/**
* Called when the Sign In button is pressed.
*/
 private void doSignIn() {
disableForm();

String username = mUsernameView.getText().toString();
String password = mPasswordView.getText().toString();

// Verify username an password on server.
mVerifyUsernamePasswordTask = new VerifyUsernamePasswordTask(new AsyncTaskListener() {
@Override
 public void onAsyncTaskFail(String errorMessage) {
mPasswordView.requestFocus();
mPasswordView.selectAll();
displayMessage(errorMessage);
}

/**
* Called when the username and password have successfully validated.
* It then calls U2F Sign.
*/
 @Override
 public void onAsyncTaskSuccess() {
Log.v(TAG, "onAsyncTaskSuccess([]): START");
doU2f();
}
});
mVerifyUsernamePasswordTask.execute(username, password);
}

protected void displayMessage(CharSequence message) {
mStatusMessageView.setText(message);
}
}

 

 

  • No labels