Skip to content

Commit

Permalink
GitHub OAuth callback URL pointing to 127.0.0.1 in development mode
Browse files Browse the repository at this point in the history
  • Loading branch information
murbanski committed Jun 26, 2012
1 parent 27d3205 commit 98c598e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions 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]
Expand All @@ -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)))

Expand Down Expand Up @@ -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]
Expand All @@ -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")
Expand All @@ -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.