<commit_before>(ns checkin.auth
  (:use [compojure.core])
  (:require [friend-oauth2.workflow :as oauth2]
            [friend-oauth2.util :refer [format-config-uri]]
            [cheshire.core :as json]
            [clj-jwt.core :as jwt]
            [environ.core :refer [env]]))

(defn get-environment-variable [name-of-env-var]
  (let [env-var (env name-of-env-var)]
    (if env-var
      env-var
      (throw (Exception. (str "No environment variable found named " name-of-env-var ". Ensure you have a profiles.clj created if running locally"))))))

(def ^:private client-config
  {:client-id     (get-environment-variable :friend-oauth2-client-id)
   :client-secret (get-environment-variable :friend-oauth2-client-secret)
   :callback {:domain "http://localhost:3000" :path "/auth/callback"}})


(def ^:private uri-config
  {:authentication-uri {:url   "https://loneworker.auth0.com/authorize"
                        :query {:client_id    (:client-id client-config)
                                :redirect_uri (format-config-uri client-config)
                                :scope        "openid name email"
                                :sso          true}}

   :access-token-uri   {:url   "https://loneworker.auth0.com/oauth/token"
                        :query {:client_id     (:client-id client-config)
                                :client_secret (:client-secret client-config)
                                :redirect_uri  (format-config-uri client-config)}}})

(def ^:private config-auth {:roles #{::user}})

(defn- parse-id-token [response]
  (let [response-body-json (:body response)
        response-body-map (json/parse-string response-body-json true)]
    (:id_token response-body-map)))

(defn- credential-fn [token]
  (let [jwt-string (:access-token token)
        jwt (jwt/str->jwt jwt-string)
        user-id (get-in jwt [:claims :sub])                 ; TODO: verify JWT
        user-name (get-in jwt [:claims :name])]             ; TODO: verify JWT

    {:identity  user-id
     :user-name user-name<commit_msg>Robin/Leanne Verify JWT for security lolz@<commit_after>(ns checkin.auth
  (:use [compojure.core])
  (:require [friend-oauth2.workflow :as oauth2]
            [friend-oauth2.util :refer [format-config-uri]]
            [cheshire.core :as json]
            [clj-jwt.core :as jwt]
            [environ.core :refer [env]]))

(defn get-environment-variable [name-of-env-var]
  (let [env-var (env name-of-env-var)]
    (if env-var
      env-var
      (throw (Exception. (str "No environment variable found named " name-of-env-var ". Ensure you have a profiles.clj created if running locally"))))))

(def ^:private client-config
  {:client-id     (get-environment-variable :friend-oauth2-client-id)
   :client-secret (get-environment-variable :friend-oauth2-client-secret)
   :callback      {:domain "http://localhost:3000" :path "/auth/callback"}})


(def ^:private uri-config
  {:authentication-uri {:url   "https://loneworker.auth0.com/authorize"
                        :query {:client_id    (:client-id client-config)
                                :redirect_uri (format-config-uri client-config)
                                :scope        "openid name email"
                                :sso          true}}

   :access-token-uri   {:url   "https://loneworker.auth0.com/oauth/token"
                        :query {:client_id     (:client-id client-config)
                                :client_secret (:client-secret client-config)
                                :redirect_uri  (format-config-uri client-config)}}})

(def ^:private config-auth {:roles #{::user}})

(defn- parse-id-token [response]
  (let [response-body-json (:body response)
        response-body-map (json/parse-string response-body-json true)]
    (:id_token response-body-map)))

(defn- credential-fn [token]
  (let [jwt-string (:access-token token)
        jwt (jwt/str->jwt jwt-string)]
    (jwt/verify jwt (get-environment-variable :friend-oauth2-client-secret))
    {:identity  (get-in jwt [:claims :sub])
     :user-name (get-in jwt [:claims :name])
{'fraction_non_alphanumeric': 0.14191176470588235, 'fraction_numerical': 0.005637254901960784, 'mean_word_length': 2.185792349726776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2445092', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1272, 'n_words': 282}