【问题标题】:Yesod.Auth no authentication and no authorizationYesod.Auth 没有认证也没有授权
【发布时间】:2021-09-14 09:17:36
【问题描述】:

我正在使用 Yesod 编写一个供个人使用的网络应用程序。我不想进行身份验证,也不想登录。 实现这一目标的最佳方法是什么?

  • 从应用程序中删除 Auth 库
  • 使用在启动时自动登录的默认隐藏用户(Auth.dummy?)
  • 或者别的什么......

【问题讨论】:

    标签: authentication haskell yesod


    【解决方案1】:

    假设您使用的是最新版本的脚手架站点,您应该能够在src/Foundation.hs 中查找isAuthorized 的定义。将整个定义替换为:

    isAuthorized _ _ = return Authorized
    

    甚至完全删除它,因为上面的定义是默认的。

    这应该足以允许访问所有页面。接下来,在您的代码中搜索maybeAuth*requireAuth* 函数的用法。确保使用maybeAuth* 的页面在返回Nothing 时按预期工作。删除对requireAuth* 的任何使用以及对其返回值的任何依赖。

    之后,您可以清理不需要的代码,但这完全是可选的:

    • Foundation.hs,您可以:
      • 删除 Yesod.Auth.DummyYesod.Auth.OpenId 导入
      • defaultLayout中删除muser <- maybeAuthPair的定义
      • 从导航栏中删除登录/注销/个人资料页面 (menuItems)
      • 删除instance Yesod App 中的authRoute 定义
      • breadcrumb 中删除AuthRProfileR
      • 删除instance YesodAuth AppisAuthenticated的定义和instance YesodAuthPersist App
    • NoFoundation.hs 中,您可以删除Yesod.Auth 导入。
    • Settings.hs 中,删除appAuthDummyLogin 字段以及在instance FromJSON AppSettings 中对其的引用
    • config/routes.yesodroutes 中删除/auth/profile 路由
    • Application.hs 中删除src/Handler/Profile.hsimport Handler.Profile
    • 删除对maybeAuth* 函数的任何剩余引用或对ProfileR 路由的引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-17
      • 2019-12-02
      • 2015-12-17
      • 2022-01-06
      • 2017-07-05
      • 2011-12-23
      相关资源
      最近更新 更多