1

I'm building a web app that will authenticate users with standard username/password pair, but will also need to authorize access to Dropbox and/or Google Drive to do some background file processing.

I'm using friend to log users in. I wanted to use friend-oauth2 but I don't know how to have different friend workflows for different URLs.

What I would like to have is:

  1. /users/* protected with workflows/interactive-form
  2. /dropbox/* and /gdrive/* protected with oauth2/workflow
  3. Any other URL public

I know how to do points 1 and 3 (with friend/authenticate and friend/authorize) but I have no clue how to get #2. Please help.

Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
Tomo
  • 3,431
  • 5
  • 25
  • 28

1 Answers1

2

You'll need to wrap your routes separately with different middleware definitions. Here is an example using compojure for route definitions:

(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)

(Thanks to this answer for the notes on different middleware for different routes)

Community
  • 1
  • 1
SteveD
  • 246
  • 1
  • 3