【问题标题】:Different friend workflows for different URLs不同 URL 的不同好友工作流程
【发布时间】:2019-09-06 19:43:07
【问题描述】:

我正在构建一个网络应用程序,它将使用标准用户名/密码对对用户进行身份验证,但还需要授权访问 Dropbox 和/或 Google Drive 以进行一些后台文件处理。

我正在使用friend 登录用户。我想使用friend-oauth2,但我不知道如何为不同的URL 设置不同的friend 工作流。

我想要的是:

  1. /users/*workflows/interactive-form 保护
  2. /dropbox/*/gdrive/*oauth2/workflow 保护
  3. 任何其他公开的 URL

我知道如何执行第 1 点和第 3 点(使用 friend/authenticatefriend/authorize),但我不知道如何获得 #2。请帮忙。

【问题讨论】:

    标签: clojure oauth-2.0


    【解决方案1】:

    您需要使用不同的中间件定义分别包装您的路由。下面是一个使用 compojure 进行路由定义的示例:

    (defroutes interactive-routes*
      ; Put your interactive routes here
      ; ...
      )
    (defroutes oauth-routes*
      ; Put your oauth routes here
      ; ...
      )
    
    (def interactive-routes
      (-> #'interactive-routes*
        (friend/authenticate {:credential-fn (partial creds/bcrypt-credential-fn users)
                              :workflows [(workflows/interactive-form)]})
      ))
    (def oauth-routes
      (-> #'oauth-routes*
        (friend/authenticate {:credential-fn (partial creds/bcrypt-credential-fn users)
                              :workflows [(oauth2/workflow)]})
      ))
    
    (defroutes all-routes
      (ANY "*" [] interactive-routes)
      (ANY "*" [] oauth-routes)
    
    ; Then do what you normally would with `all-routes` (e.g., wrap with more middleware, pass to ring server)
    

    (感谢this answer关于不同路由不同中间件的注释)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-21
      • 2013-06-25
      • 1970-01-01
      • 2011-02-05
      • 1970-01-01
      • 2014-01-25
      相关资源
      最近更新 更多