我正在按照auth0提供的指南进行身份验证,但是我厌倦了每次打开应用程序时都必须登录并且想要开始存储并利用刷新令牌。但是,我似乎无法获得刷新令牌,它始终为空。
在我的LoginActivity中,我有以下
_client = new Auth0Client(new Auth0ClientOptions
{
Domain = Resources.GetString(Resource.String.auth0_domain),
ClientId = Resources.GetString(Resource.String.auth0_client_id),
//Scope = "offline_access",
Activity = this
});
并像这样处理登录
_authorizeState = await _client.PrepareLoginAsync(new { audience = "myaudience.blahblahblah"});
protected override async void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
var loginResult = await _client.ProcessResponseAsync(intent.DataString, _authorizeState);
var sb = new StringBuilder();
if (loginResult.IsError)
{
sb.AppendLine($"An error occurred during login: {loginResult.Error}");
}
else
{
var mainActivity = new Intent(this, typeof(MainActivity));
mainActivity.PutExtra("token", loginResult.AccessToken);
StartActivity(mainActivity);
Finish();
}
}
如果我包含范围,那么我会收到一个错误,即响应不包含身份令牌。如果我不包括在内,我就不会获得刷新令牌。
答案 0 :(得分:1)
对我来说,诀窍是添加Scope行,如下所示。
原始代码:
client = new Auth0Client(new Auth0ClientOptions
{
Domain = Resources.GetString(Resource.String.auth0_domain),
ClientId = Resources.GetString(Resource.String.auth0_client_id),
Activity = this
});
改变并运作一个:
client = new Auth0Client(new Auth0ClientOptions
{
Domain = Resources.GetString(Resource.String.auth0_domain),
ClientId = Resources.GetString(Resource.String.auth0_client_id),
Activity = this,
Scope = "openid offline_access"
});
我只尝试过这个:
Scope = "offline_access"
但收到错误,直到前面的“openid”。