我试图将我的整个应用程序隐藏在身份验证后面(我将在此工作时处理授权),现在我希望每个 url 都需要 github 登录。我没有打开 github 登录页面。
我尝试将SAFE-stack 模板和"Using OAuth with Saturn"结合起来,但我没有得到 github 登录页面(我只在遵循 Saturn 指南时得到),我只是得到了正常的待办事项页面。如果我单击添加按钮,服务器会打印
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 POST http://localhost:8085/api/ITodosApi/addTodo application/json; charset=UTF-8 68
info: Microsoft.AspNetCore.Authentication.OAuth.OAuthHandler`1[[Microsoft.AspNetCore.Authentication.OAuth.OAuthOptions, Microsoft.AspNetCore.Authentication.OAuth, Version=3.1.11.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]][12]
AuthenticationScheme: GitHub was challenged.
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 10.8057ms 302
并且该项目不会添加到待办事项列表中。
除了身份验证位之外,我已经尝试删除所有内容,并且与干净的安全模板相比,我所做的唯一更改是
dotnet paket add Saturn.Extensions.Authorization --project src/Server/Server.fsproj
- 手动降级两个依赖项
paket.lock
,否则会产生错误:Microsoft.AspNetCore.Authentication.Google
to(3.1.11)
和Microsoft.AspNetCore.Authentication.OpenIdConnect
to(3.1.11)
app
将值更改Server/Server.fs
为以下(我为此问题创建了一个新的 github auth 应用程序):
let loggedInPipeline = pipeline {
requires_authentication (Giraffe.Auth.challenge "GitHub")
}
let loggedInView = router {
pipe_through loggedInPipeline
get "/" webApp
}
let appRouter = router {
forward "" loggedInView
}
let app =
application {
use_router appRouter
url "http://0.0.0.0:8085/"
memory_cache
use_static "public"
use_gzip
use_github_oauth "8cde657dfd1d3a41b9ed" "0b245e12900ff8486ade076aae07aa0deb0fd83d" "/signin-github" [("login", "githubUsername"); ("name", "fullName")]
}
run app
我的 gitHub 应用配置认证回调 url:http://localhost:8080/signin-github