Guest User

Ring Google OAuth2 with ring-oauth2

a guest
Nov 22nd, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. Here my bare testing program.
  2.  
  3. (ns ringauth2.core
  4. (:require [ring.adapter.jetty :refer [run-jetty]]
  5. [ring.middleware.defaults :refer [site-defaults wrap-defaults]]
  6. [ring.middleware.params :refer [wrap-params]]
  7. [ringauth2.oauth2 :refer [wrap-oauth2]]))
  8.  
  9. (defn handler [request]
  10. {:status 200
  11. :headers {"Content-Type" "text/html"}
  12. :body "Hello World"})
  13.  
  14.  
  15. (def authmap
  16. {:google
  17. {:authorize-uri "https://accounts.google.com/o/oauth2/v2/auth"
  18. :access-token-uri "https://www.googleapis.com/oauth2/v4/token"
  19. :client-id "xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com"
  20. :client-secret "xxxxxxxxxxxxx"
  21. :scopes ["openid" "email"]
  22. :launch-uri "/oauth2/google"
  23. :redirect-uri "/oauth2/google/callback"
  24. :landing-uri "/xxxxxxx/"}})
  25.  
  26. (run-jetty
  27. (-> handler
  28. (wrap-defaults (-> site-defaults
  29. (assoc-in [:session :cookie-attrs :same-site] :lax)))
  30. wrap-params
  31. (wrap-oauth2 authmap))
  32. {:port 3000})
  33.  
  34. ----------------------------------------------------------------------------
  35. Following are my tests for wrap-params. It works when I delete the map entry consisting of :body and http object.
  36.  
  37. (def hui (wrap-params identity))
  38. =>#'ringauth2.core/hui
  39.  
  40. (hui {:http-method :get
  41. :uri "/search"
  42. :query-string "q=clojure"})
  43. =>{:http-method :get, :uri "/search", :query-string "q=clojure", :form-params {}, :params {"q" "clojure"}, :query-params {"q" "clojure"}}
  44.  
  45. (hui {:ssl-client-cert nil,
  46. :protocol "HTTP/1.1",
  47. :remote-addr "0:0:0:0:0:0:0:1",
  48. :headers
  49. {"cookie"
  50. "_ga=GA1.1.1568628036.1504630106; JSESSIONID=XblSvyd4TRQBGr76HYELgJ6cpH6D43oP8OBLAhZc; ring-session=334f1f4e-9268-468c-add1-1c8633e36b5f",
  51. "accept"
  52. "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  53. "upgrade-insecure-requests" "1",
  54. "user-agent"
  55. "Mozilla/5.0 (X11; FreeBSD amd64; rv:57.0) Gecko/20100101 Firefox/57.0",
  56. "connection" "keep-alive",
  57. "host" "localhost:3000",
  58. "accept-language" "en-US,en;q=0.5",
  59. "accept-encoding" "gzip, deflate",
  60. "dnt" "1"},
  61. :server-port 3000,
  62. :content-length nil,
  63. :content-type nil,
  64. :character-encoding nil,
  65. :uri "/oauth2/google/callback",
  66. :server-name "localhost",
  67. :query-string
  68. "state=58icXHjzuI6N&code=4/Ku-s-yzLPns_VFCfwCh5vnAqzBpNRAbmVt8G9dAbwKo&authuser=1&hd=isgpm.de&session_state=aee5df07c30a9e6d663efa84435749938698a62d..a435&prompt=consent",
  69. :body
  70. #object[org.eclipse.jetty.server.HttpInputOverHTTP 0x30f90d3 "HttpInputOverHTTP@30f90d3"]
  71. ,
  72. :scheme :http,
  73. :request-method :get})
  74. =>java.lang.RuntimeException Unmatched delimiter: )
  75.  
  76. (hui {:protocol "HTTP/1.1",
  77. :remote-addr "0:0:0:0:0:0:0:1",
  78. :headers
  79. {"cookie"
  80. "_ga=GA1.1.1568628036.1504630106; JSESSIONID=XblSvyd4TRQBGr76HYELgJ6cpH6D43oP8OBLAhZc; ring-session=334f1f4e-9268-468c-add1-1c8633e36b5f",
  81. "accept"
  82. "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  83. "upgrade-insecure-requests" "1",
  84. "user-agent"
  85. "Mozilla/5.0 (X11; FreeBSD amd64; rv:57.0) Gecko/20100101 Firefox/57.0",
  86. "connection" "keep-alive",
  87. "host" "localhost:3000",
  88. "accept-language" "en-US,en;q=0.5",
  89. "accept-encoding" "gzip, deflate",
  90. "dnt" "1"},
  91. :server-port 3000,
  92. :content-length nil,
  93. :content-type nil,
  94. :character-encoding nil,
  95. :uri "/oauth2/google/callback",
  96. :server-name "localhost",
  97. :query-string
  98. "state=58icXHjzuI6N&code=4/Ku-s-yzLPns_VFCfwCh5vnAqzBpNRAbmVt8G9dAbwKo&authuser=1&hd=isgpm.de&session_state=aee5df07c30a9e6d663efa84435749938698a62d..a435&prompt=consent"})
  99. =>{:protocol "HTTP/1.1", :remote-addr "0:0:0:0:0:0:0:1", :params {"state" "58icXHjzuI6N", "code" "4/Ku-s-yzLPns_VFCfwCh5vnAqzBpNRAbmVt8G9dAbwKo", "authuser" "1", "hd" "isgpm.de", "session_state" "aee5df07c30a9e6d663efa84435749938698a62d..a435", "prompt" "consent"}, :headers {"host" "localhost:3000", "user-agent" "Mozilla/5.0 (X11; FreeBSD amd64; rv:57.0) Gecko/20100101 Firefox/57.0", "cookie" "_ga=GA1.1.1568628036.1504630106; JSESSIONID=XblSvyd4TRQBGr76HYELgJ6cpH6D43oP8OBLAhZc; ring-session=334f1f4e-9268-468c-add1-1c8633e36b5f", "connection" "keep-alive", "upgrade-insecure-requests" "1", "accept" "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "accept-language" "en-US,en;q=0.5", "accept-encoding" "gzip, deflate", "dnt" "1"}, :server-port 3000, :content-length nil, :form-params {}, :query-params {"state" "58icXHjzuI6N", "code" "4/Ku-s-yzLPns_VFCfwCh5vnAqzBpNRAbmVt8G9dAbwKo", "authuser" "1", "hd" "isgpm.de", "session_state" "aee5df07c30a9e6d663efa84435749938698a62d..a435", "prompt" "consent"}, :content-type nil, :character-encoding nil, :uri "/oauth2/google/callback", :server-name "localhost", :query-string "state=58icXHjzuI6N&code=4/Ku-s-yzLPns_VFCfwCh5vnAqzBpNRAbmVt8G9dAbwKo&authuser=1&hd=isgpm.de&session_state=aee5df07c30a9e6d663efa84435749938698a62d..a435&prompt=consent"}
Add Comment
Please, Sign In to add comment