Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lock Auth0 for android not returning UserProfile on authentication

I'm using Lock for providing Login functionality in my android App to users.

Here is my code: private Lock lock;

private LocalBroadcastManager broadcastManager;

private BroadcastReceiver authenticationReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        String idToken = intent.getStringExtra("com.auth0.android.lock.extra.IdToken");
        String tokenType = intent.getStringExtra("com.auth0.android.lock.extra.TokenType");
        Log.i(TAG, "User  logged in with " + idToken + " "+ tokenType);
    }
};

//Not sure use of this callback  though its not being called anytime.
private LockCallback callback = new AuthenticationCallback() {
    @Override
    public void onAuthentication(Credentials credentials) {
        Log.d(TAG, "Authenticated");
    }

    @Override
    public void onCanceled() {
        Log.d(TAG, "Authentication cancelled");
    }

    @Override
    public void onError(LockException error) {
        Log.d(TAG, "Authentication Error");
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Auth0 auth0 = new Auth0(getString(R.string.auth0_clientId), getString(R.string.auth0_domain));
    this.lock = Lock.newBuilder(auth0, callback)
            .build();
    broadcastManager = LocalBroadcastManager.getInstance(this);
    broadcastManager.registerReceiver(authenticationReceiver, new IntentFilter("com.auth0.android.lock.action.Authentication"));
    startActivity(this.lock.newIntent(this));
}

I have following two questions: 1). First of all I don't understand why it needs callback though it doesn't callback even after authentication succeeded. 2). Shouldn't LocalBroadcastManager get response with UserProfile information instead of token information?

I'm using Lock version: com.auth0.android:lock:2.0.0-beta.2

Is there any better way to do it?

Thanks in advance!

like image 506
user3089214 Avatar asked Jul 13 '16 04:07

user3089214


1 Answers

have you tried onSuccess method? I cant see in your code, that's why it's not executing after successful attempt.

Override onSuccess method in your LockCallback callback, this will return UserProfile.

/**
 * Callback for authentication API calls to Auth0 API.
 */
public interface AuthenticationCallback extends Callback {

    /**
     * Called when authentication is successful.
     * It might include user's profile and token information.
     * @param profile User's profile information or null.
     * @param token User's token information (e.g. id_token).
     */
    void onSuccess(UserProfile profile, Token token);

}

Source

like image 135
shyammakwana.me Avatar answered Oct 21 '22 09:10

shyammakwana.me