<commit_before>[![Build Status](https://travis-ci.org/blmstrm/loudmoauth.svg?branch=master)](https://travis-ci.org/blmstrm/loudmoauth)
[![Clojars](https://img.shields.io/clojars/v/loudmoauth.svg)](http://clojars.org/loudmoauth)
[![Coverage Status](https://coveralls.io/repos/github/blmstrm/loudmoauth/badge.svg?branch=master)](https://coveralls.io/github/blmstrm/loudmoauth?branch=master)
[![Dependencies Status](https://jarkeeper.com/blmstrm/loudmoauth/status.svg)](https://jarkeeper.com/blmstrm/loudmoauth)
#Loudmoauth
Loudmoauth is a single user multi provider oauth2 client library. It's been built with single user access to several different providers as its main focus.

##Quickstart
To use `loudmoauth` with Leiningen or Boot include `[loudmoauth.core "0.1.1"]`.

Require `loudmoauth` in your application:
```Clojure
(ns my-app.core
  (:require [loudmoauth.core :as lmoauth]))
```
Start with creating a map with the specific parameters regarding your oauth2 service provider, here Spotify is used an example. Note that I've stashed the client id and secret in system variables but that is up to the user:
  ```Clojure
(def spotify-oauth2-params
  {:base-url "https://accounts.spotify.com"
   :auth-endpoint "/authorize"
   :token-endpoint "/api/token"
   :client-id (System/getenv "SPOTIFY_OAUTH2_CLIENT_ID")
   :redirect-uri "http://localhost:3000/oauth2"
   :scope "playlist-read-private user-follow-modify"
   :custom-query-params {:show-dialog "true"}
   :client-secret (System/getenv "SPOTIFY_OAUTH2_CLIENT_SECRET")
   :provider :spotify})
```
Configure your http-request handler to call the function `parse-params` when the url  specified for `:redirect-uri` is called. The function `parse-params` expects a ring http response as input argument:
```Clojure
(defn handler [request]
  (condp = (:uri request)
     "/oauth2" (lm/parse-params request)
      "/interact"  (ringr/redirect (lm/user-interaction))  
    {:status 200
     :body (:uri request)}))
```
Pass the map specified earlier as an argument to the `add-provider` function.
```Clojure
(lmoauth/add-provider spotify-oauth2-params)
```
To retrieve your token call the `oauth-token` function with the keyword for the provider that you specified in your parameter map earlier:
```Clojure
(lmouath/oauth-token :spotify)
```
This should be it. For a more detailed explanation see below. For working examples see the repository [loudmoauth-examples](https://github.com/blmstrm/loudmoauth-examples).

##A bit more detail
###oauth-params map
To configure each provider one needs to provide a map of parameters describing the oauth2 service. They are as follows:

`:base-url` defines the root of the url of where our oauth2 api is located.  

`:auth-endpoint` defines the part that has to be added to the `:base-url` create the full authorization url.

`:token-endpoint` defines the part that to be added to the `:base-url` to create the full token retrival url
.
`:client-id ` defines the client ID received when registrating your application with the provider.

`:redirect-uri` defines the callback url to which the provider should make a http request when the user has authenticated through the provider.

`:scope` defines the rights your appplication is requesting from the user. This has to be a string where the different rights are separated by space.
<commit_msg>Added part about user interaction<commit_after>[![Build Status](https://travis-ci.org/blmstrm/loudmoauth.svg?branch=master)](https://travis-ci.org/blmstrm/loudmoauth)
[![Clojars](https://img.shields.io/clojars/v/loudmoauth.svg)](http://clojars.org/loudmoauth)
[![Coverage Status](https://coveralls.io/repos/github/blmstrm/loudmoauth/badge.svg?branch=master)](https://coveralls.io/github/blmstrm/loudmoauth?branch=master)
[![Dependencies Status](https://jarkeeper.com/blmstrm/loudmoauth/status.svg)](https://jarkeeper.com/blmstrm/loudmoauth)
#Loudmoauth
Loudmoauth is a single user multi provider oauth2 client library. It's been built with single user access to several different providers as its main focus.

##Quickstart
To use `loudmoauth` with Leiningen or Boot include `[loudmoauth.core "0.1.1"]`.

Require `loudmoauth` in your application:
```Clojure
(ns my-app.core
  (:require [loudmoauth.core :as lmoauth]))
```
Start with creating a map with the specific parameters regarding your oauth2 service provider, here Spotify is used an example. Note that I've stashed the client id and secret in system variables but that is up to the user:
  ```Clojure
(def spotify-oauth2-params
  {:base-url "https://accounts.spotify.com"
   :auth-endpoint "/authorize"
   :token-endpoint "/api/token"
   :client-id (System/getenv "SPOTIFY_OAUTH2_CLIENT_ID")
   :redirect-uri "http://localhost:3000/oauth2"
   :scope "playlist-read-private user-follow-modify"
   :custom-query-params {:show-dialog "true"}
   :client-secret (System/getenv "SPOTIFY_OAUTH2_CLIENT_SECRET")
   :provider :spotify})
```
Configure your http-request handler to call the function `parse-params` when the url  specified for `:redirect-uri` is called. The function `parse-params` expects a ring http response as input argument:
```Clojure
(defn handler [request]
  (condp = (:uri request)
     "/oauth2" (lm/parse-params request)
      "/interact"  (ringr/redirect (lm/user-interaction))  
    {:status 200
     :body (:uri request)}))
```
Pass the map specified earlier as an argument to the `add-provider` function.
```Clojure
(lmoauth/add-provider spotify-oauth2-params)
```
Now visit the url that will trigger a call to `lm/user-interaction`, in our case `http://localhost:3000/interact`. If everything has worked as expected on the provider side you should now see the providers authentication page. Authenticate with the provider and they should provide you with the oauth2 tokens.

To retrieve your token call the `oauth-token` function with the keyword for the provider that you specified in your parameter map earlier:
```Clojure
(lmouath/oauth-token :spotify)
```
This should be it. For a more detailed explanation see below. For working examples see the repository [loudmoauth-examples](https://github.com/blmstrm/loudmoauth-examples).

##A bit more detail
###oauth-params map
To configure each provider one needs to provide a map of parameters describing the oauth2 service. They are as follows:

`:base-url` defines the root of the url of where our oauth2 api is located.  

`:auth-endpoint` defines the part that has to be added to the `:base-url` create the full authorization url.

`:token-endpoint` defines the part that to be added to the `:base-url` to create the full token retrival url
.
`:client-id ` defines the client ID received when registrating your application with the provider.

`:redirect-uri` defines the callback url to which the provider should make a http request when the user has authenticated through the provider.

`:scope` defines the rights your appplication is requesting from the user. This has to be a string where the different rights are separated by space.

{'fraction_non_alphanumeric': 0.10635260528194147, 'fraction_numerical': 0.006423982869379015, 'mean_word_length': 4.848080133555927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '585799', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2098, 'n_words': 768}