Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在使用MVC时,如何将id_标记添加到OWIN中的响应_类型_Asp.net Mvc_Owin - Fatal编程技术网

Asp.net mvc 在使用MVC时,如何将id_标记添加到OWIN中的响应_类型

Asp.net mvc 在使用MVC时,如何将id_标记添加到OWIN中的响应_类型,asp.net-mvc,owin,Asp.net Mvc,Owin,在使用MVC时,如何将id_标记添加到OWIN中的响应_类型 app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() { ClientId = "my client id", ClientSecret = "my secret", Provider = new Goo

在使用MVC时,如何将id_标记添加到OWIN中的响应_类型

app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
                {
                    ClientId = "my client id",
                    ClientSecret = "my secret",
                    Provider = new GoogleOAuth2AuthenticationProvider
                    {
                        OnApplyRedirect = context =>
                        {
                            Dictionary<string, string> dictionary = new Dictionary<string, string>()
                            {
                                { "response_type", "code id_token" },
                                { "openid.realm", "my realm IP" }
                            };
                            var redirectUri = WebUtilities.AddQueryString(context.RedirectUri, dictionary);
                            context.Response.Redirect(redirectUri);
                        }
                    }

                });
此代码返回错误,因为重定向URI中只能包含一个响应类型参数

如何将id_令牌添加到response_type参数


仅供参考。。当迁移到OAuth2时,为了引用用户的旧Google id,这是必需的,因为他们已经切换到GUID。

下面是如何做到的

GoogleOAuth2AuthenticationOptions googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
            {
                ClientId = "my_clientid",
                ClientSecret = "my_secret",
                Provider = new GoogleOAuth2AuthenticationProvider
                {
                    OnApplyRedirect = context =>
                    {
                        Dictionary<string, string> dictionary = new Dictionary<string, string>()
                        {
                            { "openid.realm", "my realm URL"},
                        };
                        string redirect = context.RedirectUri.Replace("response_type=code", "response_type=code id_token");
                        var redirectUri = WebUtilities.AddQueryString(redirect, dictionary);
                        context.Response.Redirect(redirectUri);
                    },                    

                },
            };

为了将来的参考,ASP.NET MVC有一些特定的标记-您最初使用的标记是针对有关模式的问题,而不是特定的实现。Tieson-我查看了GoogleAuthenticationHandler.ApplyResponseChallengeAsync,它调用了OnApplyRedirect。我没有看到“response\u type”设置在哪里,但我看到了“openid.realm”。我想你必须重建整个字符串。