OAuth user login

This is an example about how you can use topoos OAuth 2.0 identification in your app by using topoos Android SDK.

Just include this login button on your layout (or fire the event with other method that you want):

<Button android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onLoginClick"
        android:text="LogIn with topoos" />

And make the OAuth 2.0 API call with the SDK in the event handler. As you can see, you will get an accreditation response on your onActivityResult method, where you can manage get and manage your new valid AccessTokenOAuth object (which is now automatically saved on preferences).

private static String CLIENT_ID = "YOUR_APP_CLIENT_ID";
private int REQUESTCODE_LOGIN = 0;

public void onLoginClick(View v) {

	Intent intent = new Intent(this, LoginActivity.class);
	intent.putExtra(LoginActivity.CLIENT_ID, CLIENT_ID);
	startActivityForResult(intent, REQUESTCODE_LOGIN);

}

@Override
protected void onActivityResult
          (int requestCode, int resultCode, Intent data) {

	if (requestCode == REQUESTCODE_LOGIN) {
		switch (resultCode) {
		case LoginActivity.RESULT_OK:
			if (AccessTokenOAuth.GetAccessToken(this).isValid()) {
				//Your app is authorized by the user
			}
			break;
		case LoginActivity.RESULT_CANCELED:
			break;
		case LoginActivity.RESULT_TOPOOSERROR:
			break;
		default:
			break;
		}
	}
}

AndroidManifest.xml changes

Add the lines below to your AndroidManifest file.

<uses-permission android:name="android.permission.INTERNET" />
<activity android:name="topoos.LoginActivity" ></activity>

 

Source Code

You can get this project source code in topoos GitHub repository.