C# 使用dotnet core 2.0的google oauth高清参数器
我想将添加到我的OAuth工作流中,以限制对我的应用程序的登录访问,但我还没有找到任何有关dotnet core的文档 到目前为止,这就是我所做的:C# 使用dotnet core 2.0的google oauth高清参数器,c#,oauth,google-api,.net-core,C#,Oauth,Google Api,.net Core,我想将添加到我的OAuth工作流中,以限制对我的应用程序的登录访问,但我还没有找到任何有关dotnet core的文档 到目前为止,这就是我所做的: services.AddAuthentication().AddGoogle(g => { g.ClientId = Configuration["google-client-id"]; g.ClientSecret = Configuration["google-client-secret"]; g.ClaimAct
services.AddAuthentication().AddGoogle(g =>
{
g.ClientId = Configuration["google-client-id"];
g.ClientSecret = Configuration["google-client-secret"];
g.ClaimActions.MapJsonSubKey(PlatformKeys.GoogleAuthImageUrl, "image", "url");
});
如何将该参数添加到配置中?这是自定义声明吗?我基于 公共类CustomGoogleHandler:OAuthHandler { public CustomGoogleHandler(IOptionsMonitor选项、iLogger工厂记录器、URLCoder编码器、ISystemClock时钟) :基本(选项、记录器、编码器、时钟) { } 受保护的重写异步任务CreateTicketAsync(ClaimsEntity标识、AuthenticationProperties属性、OAuthTokenResponse令牌) { //为简单起见省略了代码 } 受保护的重写字符串BuildChallengeUrl(AuthenticationProperties属性,字符串重定向URI) { 字典字典=新字典(StringComparer.OrdinalIgnoreCase) { {“响应类型”,“代码”}, {“client_id”,Options.ClientId}, {“重定向uri”,重定向uri} }; AddQueryString(字典,属性,“范围”,FormatScope()); AddQueryString(字典,属性,“访问类型”,选项.AccessType); AddQueryString(dictionary,properties,“hd”,Options.HostedDomain); AddQueryString(字典、属性、“批准提示”); AddQueryString(字典、属性、“提示”); AddQueryString(字典、属性、“登录提示”); AddQueryString(字典、属性,“包括授予的范围”); string str=Options.StateDataFormat.Protect(属性); 添加(“state”,str); 返回queryhelp.AddQueryString(Options.AuthorizationEndpoint,dictionary); } 私有静态void AddQueryString(IDictionary querystring、AuthenticationProperties属性、字符串名称、字符串defaultValue=null) { //为简单起见省略了代码 } } 我刚刚将自定义域属性添加到我的自定义google选项中,如下所示:
public class CustomGoogleOptions : GoogleOptions
{
/// <summary>
/// Support for HostedDomain option
/// https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
/// </summary>
public string HostedDomain { get; set; }
}
公共类CustomGoogleOptions:GoogleOptions
{
///
///对HostedDomain选项的支持
/// https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
///
公共字符串HostedDomain{get;set;}
}
我希望这有帮助 我已经基于 公共类CustomGoogleHandler:OAuthHandler { public CustomGoogleHandler(IOptionsMonitor选项、iLogger工厂记录器、URLCoder编码器、ISystemClock时钟) :基本(选项、记录器、编码器、时钟) { } 受保护的重写异步任务CreateTicketAsync(ClaimsEntity标识、AuthenticationProperties属性、OAuthTokenResponse令牌) { //为简单起见省略了代码 } 受保护的重写字符串BuildChallengeUrl(AuthenticationProperties属性,字符串重定向URI) { 字典字典=新字典(StringComparer.OrdinalIgnoreCase) { {“响应类型”,“代码”}, {“client_id”,Options.ClientId}, {“重定向uri”,重定向uri} }; AddQueryString(字典,属性,“范围”,FormatScope()); AddQueryString(字典,属性,“访问类型”,选项.AccessType); AddQueryString(dictionary,properties,“hd”,Options.HostedDomain); AddQueryString(字典、属性、“批准提示”); AddQueryString(字典、属性、“提示”); AddQueryString(字典、属性、“登录提示”); AddQueryString(字典、属性,“包括授予的范围”); string str=Options.StateDataFormat.Protect(属性); 添加(“state”,str); 返回queryhelp.AddQueryString(Options.AuthorizationEndpoint,dictionary); } 私有静态void AddQueryString(IDictionary querystring、AuthenticationProperties属性、字符串名称、字符串defaultValue=null) { //为简单起见省略了代码 } } 我刚刚将自定义域属性添加到我的自定义google选项中,如下所示:
public class CustomGoogleOptions : GoogleOptions
{
/// <summary>
/// Support for HostedDomain option
/// https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
/// </summary>
public string HostedDomain { get; set; }
}
公共类CustomGoogleOptions:GoogleOptions
{
///
///对HostedDomain选项的支持
/// https://developers.google.com/identity/protocols/OpenIDConnect#hd-param
///
公共字符串HostedDomain{get;set;}
}
我希望这有帮助