Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

GitHub OAuth callback URL pointing to 127.0.0.1 in development mode

  • Loading branch information...
commit 98c598ee1767ba21ba5ee002a5dc98f451347501 1 parent 27d3205
@murbanski authored
Showing with 11 additions and 11 deletions.
  1. +3 −2 README.md
  2. +8 −9 src/pull_panel/views/welcome.clj
View
5 README.md
@@ -6,11 +6,12 @@ on one screen.
## Usage
You must first register this as a github application in order to use Oauth, and set environment variables
-for GITHUB_CLIENT_ID and GITHUB_SECRET.
+for GITHUB_CLIENT_ID and GITHUB_SECRET. For development mode you have to set your app "Callback URL" on GitHub
+to `http://lvh.me:8080`. This domain points to `127.0.0.1` and OAuth integration becomes a piece of cake.
```bash
lein deps
-lein run
+GITHUB_CLIENT_ID=XXX GITHUB_SECRET=XXX lein run
```
## License
View
17 src/pull_panel/views/welcome.clj
@@ -1,7 +1,8 @@
(ns pull-panel.views.welcome
(:require [pull-panel.views.common :as common])
(:use [noir.core :only [defpage]]
- [hiccup.core :only [html]])
+ [hiccup.core :only [html]]
+ [noir.options :only [dev-mode?]])
(:require [noir.response :as resp]
[clj-http.client :as client]
[noir.session :as session]
@@ -15,6 +16,10 @@
(session/flash-put! (str "Deleted repo " user "/" repo) )
(resp/redirect "/"))
+(defn github-auth-callback-host []
+ "When server is started in development mode it returns lvh.me URL that points to 127.0.0.1"
+ (if (dev-mode?) "http://lvh.me:8080" "https://pullpanel.herokuapp.com"))
+
(defn pull-list [pulls]
(page-helpers/ordered-list (map #(page-helpers/link-to (% "html_url") (% "body")) pulls)))
@@ -77,7 +82,7 @@
(resp/redirect
(str "https://github.com/login/oauth/authorize?"
"client_id=" (get (System/getenv) "GITHUB_CLIENT_ID") "&"
- "redirect_uri=https://pullpanel.herokuapp.com/auth/github-callback&"
+ "redirect_uri=" (github-auth-callback-host) "/auth/github-callback&"
"scope=repo")))
(defn delete-repo-form [user repo]
@@ -97,12 +102,6 @@
(session/flash-put! "You have been logged out")
(resp/redirect "/"))
-(defpage "/set-token" {:keys [token]}
- "Hacky for testing: set the API token given to your app for local testing"
- (session/put! :token token)
- (session/flash-put! (str "Set token to " token) )
- (resp/redirect "/"))
-
(defpage "/auth/github-callback" {:keys [code]}
(let [res (client/post "https://github.com/login/oauth/access_token"
{:form-params {:client_id (get (System/getenv) "GITHUB_CLIENT_ID")
@@ -111,4 +110,4 @@
:accept :json})]
((session/put! :token ((json/parse-string (res :body)) "access_token"))
(session/flash-put! (str "Github user session created" ))
- (resp/redirect "/"))))
+ (resp/redirect "/"))))

0 comments on commit 98c598e

Please sign in to comment.
Something went wrong with that request. Please try again.