【问题标题】:Lock Auth0 for android not returning UserProfile on authentication为 android 锁定 Auth0 在身份验证时不返回 UserProfile
【发布时间】:2016-11-15 12:11:32
【问题描述】:

我正在使用 Lock 在我的 android 应用程序中向用户提供登录功能。

这是我的代码: 私锁锁;

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));
}

我有以下两个问题: 1)。首先,我不明白为什么它需要回调,尽管即使在身份验证成功后它也不会回调。 2)。 LocalBroadcastManager 不应该使用 UserProfile 信息而不是令牌信息来获取响应吗?

我正在使用锁定版本:com.auth0.android:lock:2.0.0-beta.2

有没有更好的办法?

提前致谢!

【问题讨论】:

  • 你试过回答吗?
  • 不,我正在使用另一个版本的 android:lock

标签: android broadcastreceiver locking auth0


【解决方案1】:

你试过 onSuccess 方法吗?我在你的代码中看不到,这就是为什么它在成功尝试后没有执行。

在 LockCallback callback 中覆盖 onSuccess 方法,这将返回 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 2020-06-11
    • 1970-01-01
    • 2016-04-22
    • 2021-01-01
    相关资源
    最近更新 更多