Skip to content

Instantly share code, notes, and snippets.

@deadprogram
Created November 19, 2012 00:36

Revisions

  1. deadprogram revised this gist Nov 19, 2012. 1 changed file with 24 additions and 23 deletions.
    47 changes: 24 additions & 23 deletions welcome.clj
    Original file line number Diff line number Diff line change
    @@ -9,30 +9,31 @@

    (defpage "/" []
    (let []
    (common/layout
    [:div
    [:h1 "ATT OAuth Demo"]
    [:a {:href "/auth"} "Get Profile"]])))
    (common/layout
    [:div
    [:h1 "ATT OAuth Demo"]
    [:a {:href "/auth"} "Get Profile"]])))

    (defpage "/auth" []
    (redirect (build-authorization-url
    { :authorization-url (str "https://" (get (System/getenv) "AUTH_SERVER") "/oauth/authorize")
    :client-id (get (System/getenv) "CLIENT_ID")}
    { :redirect-uri "http://localhost:4567/auth/callback"
    :scope :profile })))
    (let [
    auth-url (build-authorization-url
    { :authorization-url (str "https://" (get (System/getenv) "AUTH_SERVER") "/oauth/authorize")
    :client-id (get (System/getenv) "CLIENT_ID")}
    { :redirect-uri "http://localhost:4567/auth/callback"
    :scope :profile })]
    (redirect auth-url)))

    (defpage "/auth/callback" {:keys [code]}
    (let [
    token (fetch-token {:token-url (str "https://" (get (System/getenv) "AUTH_SERVER") "/oauth/token")
    :client-id (get (System/getenv) "CLIENT_ID")
    :client-secret (get (System/getenv) "CLIENT_SECRET")}
    {:code code
    :insecure? true
    :redirect-uri "http://localhost:4567/auth/callback"})
    profile-data (:body (client/get (str "https://" (get (System/getenv) "AUTH_SERVER") "/me.json")
    { :as :json :accept :json :oauth-token (:access-token token) :insecure? true }))]

    (common/layout
    [:div
    [:h1 "profile-data"]
    [:p (str profile-data)]])))
    (let [
    token (fetch-token { :token-url (str "https://" (get (System/getenv) "AUTH_SERVER") "/oauth/token")
    :client-id (get (System/getenv) "CLIENT_ID")
    :client-secret (get (System/getenv) "CLIENT_SECRET")}
    { :code code
    :insecure? true
    :redirect-uri "http://localhost:4567/auth/callback"})
    profile-data (:body (client/get (str "https://" (get (System/getenv) "AUTH_SERVER") "/me.json")
    { :as :json :accept :json :oauth-token (:access-token token) :insecure? true }))]
    (common/layout
    [:div
    [:h1 "profile-data"]
    [:p (str profile-data)]])))
  2. deadprogram revised this gist Nov 19, 2012. 2 changed files with 15 additions and 15 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,11 @@ Example of accessing ATT OAuth in Clojure using noir.

    ```bash
    lein deps
    lein run
    CLIENT_ID=XXX CLIENT_SECRET=YYY AUTH_SERVER=xyz.com lein run
    ```

    ## License

    Copyright (C) 2012 The Hybrid Group

    Distributed under the MIT License
    Distributed under the MIT License
    26 changes: 13 additions & 13 deletions welcome.clj
    Original file line number Diff line number Diff line change
    @@ -2,36 +2,36 @@
    (:require [att-oauth-client.views.common :as common]
    [clj-http.client :as client])
    (:use [noir.core :only [defpage custom-handler]]
    [noir.response :only [redirect]]
    [noir.response :only [redirect]]
    [hiccup.core :only [html]]
    [oauthentic.core]))


    (defpage "/" []
    (let []
    (common/layout
    [:div
    [:h1 "ATT OAuth Demo"]
    [:a {:href "/auth"} "Get Profile"]])))
    (common/layout
    [:div
    [:h1 "ATT OAuth Demo"]
    [:a {:href "/auth"} "Get Profile"]])))

    (defpage "/auth" []
    (redirect (build-authorization-url
    { :authorization-url "https://75.55.105.49/oauth/authorize"
    { :authorization-url (str "https://" (get (System/getenv) "AUTH_SERVER") "/oauth/authorize")
    :client-id (get (System/getenv) "CLIENT_ID")}
    { :redirect-uri "http://localhost:4567/auth/callback"
    { :redirect-uri "http://localhost:4567/auth/callback"
    :scope :profile })))

    (defpage "/auth/callback" {:keys [code]}
    (let [
    token (fetch-token {:token-url "https://75.55.105.49/oauth/token"
    token (fetch-token {:token-url (str "https://" (get (System/getenv) "AUTH_SERVER") "/oauth/token")
    :client-id (get (System/getenv) "CLIENT_ID")
    :client-secret (get (System/getenv) "CLIENT_SECRET")}
    {:code code
    :insecure? true
    :redirect-uri "http://localhost:4567/auth/callback"})
    profile-data (:body (client/get "https://75.55.105.49/me.json"
    { :as :json :accept :json :oauth-token (:access-token token) :insecure? true }
    ))]
    :insecure? true
    :redirect-uri "http://localhost:4567/auth/callback"})
    profile-data (:body (client/get (str "https://" (get (System/getenv) "AUTH_SERVER") "/me.json")
    { :as :json :accept :json :oauth-token (:access-token token) :insecure? true }))]

    (common/layout
    [:div
    [:h1 "profile-data"]
  3. deadprogram revised this gist Nov 19, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions welcome.clj
    Original file line number Diff line number Diff line change
    @@ -16,20 +16,20 @@

    (defpage "/auth" []
    (redirect (build-authorization-url
    { :authorization-url "https://75.55.105.49/oauth/authorize"
    { :authorization-url "https://75.55.105.49/oauth/authorize"
    :client-id (get (System/getenv) "CLIENT_ID")}
    { :redirect-uri "http://localhost:4567/auth/callback"
    :scope :profile })))

    (defpage "/auth/callback" {:keys [code]}
    (let [
    token (fetch-token {:token-url "https://75.55.105.49/oauth/token"
    token (fetch-token {:token-url "https://75.55.105.49/oauth/token"
    :client-id (get (System/getenv) "CLIENT_ID")
    :client-secret (get (System/getenv) "CLIENT_SECRET")}
    {:code code
    :insecure? true
    :redirect-uri "http://localhost:4567/auth/callback"})
    profile-data (:body (client/get "https://75.55.105.49/me.json"
    profile-data (:body (client/get "https://75.55.105.49/me.json"
    { :as :json :accept :json :oauth-token (:access-token token) :insecure? true }
    ))]
    (common/layout
  4. deadprogram created this gist Nov 19, 2012.
    16 changes: 16 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # ATT OAuth2 Clojure Client

    Example of accessing ATT OAuth in Clojure using noir.

    ## Usage

    ```bash
    lein deps
    lein run
    ```

    ## License

    Copyright (C) 2012 The Hybrid Group

    Distributed under the MIT License
    6 changes: 6 additions & 0 deletions project.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    (defproject att-oauth-client "0.1.0-SNAPSHOT"
    :description "Example of accessing ATT OAuth in Clojure using noir"
    :dependencies [[org.clojure/clojure "1.3.0"]
    [noir "1.2.1"]
    [org.clojars.deadprogram/oauthentic "1.0.4"]]
    :main att-oauth-client.server)
    10 changes: 10 additions & 0 deletions server.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    (ns att-oauth-client.server
    (:require [noir.server :as server]))

    (server/load-views "src/att_oauth_client/views/")

    (defn -main [& m]
    (let [mode (keyword (or (first m) :dev))
    port (Integer. (get (System/getenv) "PORT" "4567"))]
    (server/start port {:mode mode
    :ns 'att-oauth-client})))
    38 changes: 38 additions & 0 deletions welcome.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    (ns att-oauth-client.views.welcome
    (:require [att-oauth-client.views.common :as common]
    [clj-http.client :as client])
    (:use [noir.core :only [defpage custom-handler]]
    [noir.response :only [redirect]]
    [hiccup.core :only [html]]
    [oauthentic.core]))


    (defpage "/" []
    (let []
    (common/layout
    [:div
    [:h1 "ATT OAuth Demo"]
    [:a {:href "/auth"} "Get Profile"]])))

    (defpage "/auth" []
    (redirect (build-authorization-url
    { :authorization-url "https://75.55.105.49/oauth/authorize"
    :client-id (get (System/getenv) "CLIENT_ID")}
    { :redirect-uri "http://localhost:4567/auth/callback"
    :scope :profile })))

    (defpage "/auth/callback" {:keys [code]}
    (let [
    token (fetch-token {:token-url "https://75.55.105.49/oauth/token"
    :client-id (get (System/getenv) "CLIENT_ID")
    :client-secret (get (System/getenv) "CLIENT_SECRET")}
    {:code code
    :insecure? true
    :redirect-uri "http://localhost:4567/auth/callback"})
    profile-data (:body (client/get "https://75.55.105.49/me.json"
    { :as :json :accept :json :oauth-token (:access-token token) :insecure? true }
    ))]
    (common/layout
    [:div
    [:h1 "profile-data"]
    [:p (str profile-data)]])))