Я думаю, что мой тест — самый простой из возможных тестов неявного потока. Использование встроенной опции для завершения быстрой демонстрации. К сожалению, работает не полностью. Я не получаю жетон обратно.
Я думаю, что это код, который делает большую часть работы.
Клиент
new Client {
RequireConsent = false,
Enabled = true,
ClientId = "implicitclient",
ClientName = "Implicit Client",
Flow = Flows.Implicit,
RedirectUris = new List<string>
{
"https://localhost:44310/identityclaim"
},
AllowedScopes = new List<string> {
Constants.StandardScopes.OpenId,
Constants.StandardScopes.Profile,
Constants.StandardScopes.Email,
"test"
},
AccessTokenType = AccessTokenType.Jwt
}
};
Область
var scopes = new List<Scope>
{
new Scope
{
Enabled = true,
Name = "test",
Description = "Test",
Type = ScopeType.Resource
}
};
scopes.AddRange(StandardScopes.All);
return scopes;
Пользователь
new InMemoryUser
{
Username = "User",
Password = "secret",
Subject = "1",
}
Аутентификация
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "https://localhost:44309/context",
RequiredScopes = new[] { "test" }
});
app.UseCors(CorsOptions.AllowAll);
// web api configuration
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
app.UseWebApi(config);
Настройка
return builder.Map("/context",
app =>
{
app.UseIdentityServer(new IdentityServerOptions
{
SiteName = "SiteName",
SigningCertificate = CertLoader.Load(),
Factory = new IdentityServerServiceFactory()
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get())
.UseInMemoryUsers(Users.Get()),
RequireSsl = true,
LoggingOptions = new LoggingOptions { EnableHttpLogging = true,
EnableWebApiDiagnostics = true}
});
});
Текущий статус
Когда я вхожу во встроенный IdentityServer3, я вижу это.
Client Application Permissions
You have not given permission to any applications
Когда я пробую этот URL-адрес в браузере, надеясь вернуть токен, я вижу ошибку. Я тщательно закодировал все в base64.
https://localhost:44309/context/connect/authorize?client_id=c2FtcGxlYXBpY2xpZW50=&redirect_uri=aHR0cHM6Ly9sb2NhbGhvc3Q6NDQzMTAvY2xhaW1z&response_type=dG9rZW4=&scope=b3BlbmlkIGVtYWlsIG15V2ViQXBp&state=abc&nonce=xyz
The client application made an invalid request.