Неявный поток IdentityServer3

Я думаю, что мой тест — самый простой из возможных тестов неявного потока. Использование встроенной опции для завершения быстрой демонстрации. К сожалению, работает не полностью. Я не получаю жетон обратно.

Я думаю, что это код, который делает большую часть работы.

Клиент

          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.

person Mohan Radhakrishnan    schedule 11.02.2016    source источник
comment
redirect_uri мне кажется странным.   -  person Brock Allen    schedule 23.03.2016
comment
Да. Я изменил URL на незакодированный. Решено.   -  person Mohan Radhakrishnan    schedule 23.05.2016


Ответы (2)


можете ли вы проверить AllowedCorsOrigins после RedirectUris,

в то же время в вашем запросе URL-адрес client_id выглядит недействительным

client_id= < id of the Client>

https://localhost:44309 /context/connect/authorize?client_id=c2FtcGxlYXBpY2xpZW50=&redirect_uri=aHR0cHM6Ly9sb2NhbGhvc3Q6NDQzMTAvY2xhaW1z&response_type=dG9rZW4=&scope=b3BlbmlkIGVtYWlsIG15V2ViQXBp&state=abc&nonce>=

так должно быть ниже

https://localhost:44309/context/connect/authorize?client_id=implicitclient&redirect_uri=aHR0cHM6Ly9sb2NhbGhvc3Q6NDQzMTAvY2xhaW1z&response_type=dG9rZW4=&scope=b3BlbmlkIGVtYWlsIG15V2ViQXBp&state=abc&nonce=xyz

person Ruwanthaka    schedule 17.05.2016

Ваш запрос на авторизацию должен быть таким: https://localhost:44309/connect/authorize?clientId=implicitclient&redirect_uri=https://localhost:44310/identityclaim&reponse_type=id_token&scope=openid%20test&nonce=none

Не кодируйте свой запрос в base64, браузер автоматически закодирует URL-адрес. http://www.w3schools.com/tags/ref_urlencode.asp

person Alain Croisetière    schedule 19.11.2016