Клиент Identity Server:
//wpf sample
new Client
{
ClientId = "native.code",
ClientName = "Native Client (Code with PKCE)",
RedirectUris = { "http://127.0.0.1/sample-wpf-app" },
//PostLogoutRedirectUris = { "https://notused" },
RequireClientSecret = false,
AllowedGrantTypes = GrantTypes.Code,
AllowAccessTokensViaBrowser = true,
RequirePkce = true,
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.OfflineAccess,
"fiver_auth_api"
},
AllowOfflineAccess = true,
//Access token life time is 7200 seconds (2 hour)
AccessTokenLifetime = 7200,
//Identity token life time is 7200 seconds (2 hour)
IdentityTokenLifetime = 7200,
RefreshTokenUsage = TokenUsage.ReUse
}
Приложение WPF:
var options = new OidcClientOptions()
{
//redirect to identity server
Authority = "http://localhost:5000/",
ClientId = "native.code",
Scope = "openid profile offline_access fiver_auth_api",
//redirect back to app if auth success
RedirectUri = "http://127.0.0.1/sample-wpf-app",
ResponseMode = OidcClientOptions.AuthorizeResponseMode.FormPost,
Flow = OidcClientOptions.AuthenticationFlow.AuthorizationCode,
Browser = new WpfEmbeddedBrowser()
};
Я пытаюсь соединить идентификационный сервер с приложением wpf, но я всегда получаю 401.
Сервер идентификации работает на: http://localhost:5000/
WPF: http://127.0.0.1/sample-wpf-app
Я проверяю токен, и он хороший. Я также включаю AllowOfflineAccess = true.
Почему я всегда получаю эту ошибку?
Редактировать: Web Api:
var accessToken = token;
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
//on button click call Web api Get movies
//Initialize HTTP Client
client.BaseAddress = new Uri("http://localhost:5001");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
try
{
HttpResponseMessage response = client.GetAsync("/movies/get").Result;
MessageBox.Show(response.Content.ReadAsStringAsync().Result);
}
catch (Exception)
{
MessageBox.Show("Movies not Found");
}