我想知道如何在IdentityServer和外部身份验证提供程序(例如Google)之间自行连接?我认为这是在使用带有隐式授权的IdentityServer4 QuickStart UI时给出的;例如外部登录触发器已经连线。
但我正在使用资源所有者密码授予,以便我可以使用自己的登录UI,无法弄清楚如何连接IS和外部身份验证。
我尝试添加Google,然后转到localhost:5001/signin-google
,但收到了错误消息。我想我需要更多设置但不确定如何。有没有人这样做过?
我还在Google控制台中注册了localhost:5001/signin-google
以获取authrorized来源。
这是我的配置:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(options =>
{
options.Authority = _authority;
options.ApiName = "my-api";
options.RequireHttpsMetadata = false;
//options.ApiSecret = "secret";
options.SupportedTokens = SupportedTokens.Both;
});
// add google
services.AddAuthentication()
.AddGoogle("Google", options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.ClientId = "b5lge4nj8djnr63lm25rbl4nl0gct73v.apps.googleusercontent.com";
options.ClientSecret = "vfRXJmEXnKuIsSnHxOn_f";
});
这是日志:
2017-12-30 21:43:50.641 +00:00 [INF] Error from RemoteAuthentication: The oauth state was missing or invalid..
2017-12-30 21:43:50.646 +00:00 [ERR] An unhandled exception has occurred while executing the request
System.Exception: The oauth state was missing or invalid.
at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.<HandleRequestAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at IdentityServer4.Hosting.FederatedSignOut.AuthenticationRequestHandlerWrapper.<HandleRequestAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
2017-12-30 22:00:38.055 +00:00 [INF] Error from RemoteAuthentication: The oauth state was missing or invalid..
2017-12-30 22:00:38.079 +00:00 [ERR] An unhandled exception has occurred while executing the request
System.Exception: The oauth state was missing or invalid.
at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.<HandleRequestAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at IdentityServer4.Hosting.FederatedSignOut.AuthenticationRequestHandlerWrapper.<HandleRequestAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
Update1 :当我添加CallbackPath
时,localhost:5001/signin-google
现在返回404 Not Found。
// add google
services.AddAuthentication()
.AddGoogle("Google", options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.ClientId = "b5lge4nj8djnr63lm25rbl4nl0gct73v.apps.googleusercontent.com";
options.ClientSecret = "vfRXJmEXnKuIsSnHxOn_f";
options.CallbackPath = "/home";
});