Жетон обновления всегда пуст, это мой код:
new Client
{
ClientId = "mvc",
ClientName = "MVC Client",
RequireConsent = false,
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
AllowAccessTokensViaBrowser = true,
ClientSecrets = {new Secret("secret".Sha256())},
RedirectUris = { "http://localhost:7002/Account/callback" }, //{ "http://localhost:7002/signin-oidc" }, //
PostLogoutRedirectUris = { "http://localhost:7002/signout-callback-oidc" },
AllowedScopes = new List<string>
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.OfflineAccess,
"api1"
},
AllowOfflineAccess = true,
AlwaysIncludeUserClaimsInIdToken = true
}
И это мой MVCClient
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = "http://localhost:7000";
options.RequireHttpsMetadata = false;
options.ClientId = "mvc";
options.ClientSecret = "secret";
options.ResponseType = "code id_token token";
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("api1");
options.Scope.Add("offline_access");
});
Я авторизируюсь, создав URL авторизации, и вот какЯ создаю это:
var host = _context.HttpContext.Request.Host.Host;
var discoveryClient = new DiscoveryClient(Configuration["auth:oidc:authority"]);
var disco = await discoveryClient.GetAsync();
var request = new RequestUrl(disco.AuthorizeEndpoint);
authorizeUrl = request.CreateAuthorizeUrl(
clientId: "mvc",
responseType: "code id_token token",
responseMode: OidcConstants.ResponseModes.FormPost,
scope: "openid profile api1 offline_access",
redirectUri: "http://localhost:7002/Account/callback", //"http://localhost:7002/signin-oidc", //
state: CryptoRandom.CreateUniqueId(),
nonce: CryptoRandom.CreateUniqueId(),
acrValues: host);
return Redirect(authorizeUrl);
Я перенаправлен на страницу входа в систему, я делаю вход в систему, и как только я вошел в систему, и возвращаюсь в CallBack () (в HomeController), я получаю все, кроме пустогоrefresh_token:
public async Task<IActionResult> Callback()
{
var code = Request.Form["code"];
var tokenType = Request.Form["token_type"];
var idToken = Request.Form["id_token"];
var scope = Request.Form["scope"];
var state = Request.Form["state"];
var session_state = Request.Form["session_state"];
var error = Request.Form["error"];
var expiresAt = Request.Form["expires_in"];
var accessToken = Request.Form["access_token"];
var refreshToken = Request.Form["refresh_token"];
}
Подведем итоги: refresh_token является пустым {}, а не нулевым.Чтобы проверить это другим способом, к методу about я добавил [authorize], и если я войду в систему, нажав только там, то у меня будет файл refresh_token.
Я что-то упустил?