微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

具有 github 授权的安全堆栈

如何解决具有 github 授权的安全堆栈

我正在尝试将我的整个应用程序隐藏在身份验证之后(当这有效时我会处理授权),现在我希望每个 url 都需要 github 登录。我没有打开 github 登录页面

我尝试将 SAFE-stack template"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 

并且该项目未添加到待办事项列表中。

我已经尝试去掉除了身份验证位之外的所有内容,与干净安全的模板相比,我所做的唯一更改是

  1. dotnet paket add Saturn.Extensions.Authorization --project src/Server/Server.fsproj
  2. 手动将 paket.lock 中的两个依赖项降级,否则会导致错误Microsoft.AspNetCore.Authentication.Google(3.1.11)Microsoft.AspNetCore.Authentication.OpenIdConnect(3.1.11)
  3. 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 应用配置身份验证回调网址:http://localhost:8080/signin-github

解决方法

您是否为 https 参数尝试过 http 而不是 url

替换

url "http://0.0.0.0:8085"

url "https://0.0.0.0:8085"

这为我解决了问题。

演示代码:https://github.com/functionalfriday/fsharp-saturn-demos

,

我得到了解决此问题的帮助,仅适用于 AzureAD。可以在此处找到博客文章 https://www.compositional-it.com/news-blog/safe-stack-authentication-with-active-directory-part-2/。 github 应该是一样的。我需要做的是对 webpack.config.jsServer.fsbuild.fsx

进行一些更改

webpack.config.js

devServerProxy: {
    // redirect all requests to the server on port 8085
    '**': {
//...
var CONFIG = {
    appHtmlTemplate: './src/Client/app.html',//...
var commonPlugins = [
    new HtmlWebpackPlugin({
        filename: 'app.html',//...
var CONFIG = {
    // ... other webpack config settings
    outputDir: './src/Server/public',// ...
    devServer: {
        // ...other dev server config settings
        writeToDisk: true
    },

Server.fs

let authScheme = "AzureAD"

let isDevelopment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") = Environments.Development;

let noAuthenticationRequired nxt ctx = task { return! nxt ctx }

let authChallenge : HttpFunc -> HttpContext -> HttpFuncResult =
    requiresAuthentication (Auth.challenge authScheme)

let routes =
    choose [
        route "/" >=> authChallenge >=>  htmlFile "public/app.html"
    ]

build.fsx:

let serverPublicPath = Path.getFullName "./src/Server/public"
let clientPublicPath = Path.getFullName "./src/Client/public"
Target.create "Clean" (fun _ ->
    Shell.cleanDir deployDir
    Shell.cleanDir serverPublicPath)
Target.create "Run" (fun _ ->
    Shell.copyDir serverPublicPath clientPublicPath FileFilter.allFiles
    //... other commands

如果您在本地工作,例如 Firefox,由于前面提到的 cookie 问题,您将需要使用非 Chrome 浏览器。

打开隐私浏览窗口是个好主意,以确保您还没有登录帐户等。

如果您遇到问题,请检查您是否有

  • 在 Azure 中正确设置应用的 Active Directory 注册
  • appsettings.json 中向您的服务器添加了所需的 AD 配置,包括您在 AD 注册中设置的登录/注销回调 URL。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?