An oauth2 module in crystal

Requirement :

Installation :

Add this to your application's shard.yml:

dependencies:
  croauth2:
    github: ndudnicz/croauth2

Example :

require "croauth2"

CLIENT_ID = ENV["CLIENT_ID"]
CLIENT_SECRET = ENV["CLIENT_SECRET"]

o = Croauth2.new "https://api.intra.42.fr", CLIENT_ID, CLIENT_SECRET
o.get_token_from_credentials()
res = o.get("/v2/users", params: {"page" => { "number" => "2" } })
puts res.body

API :

Constructor :

.new(endpoint: String, client_id: String, client_secret: String)

        create a new Myoauth2 client

Instance Methods Summary :

.get(path: String, params : Hash(String, String) = nil) :
HTTP::Client::Response

        Executes a GET request with the params passed as url encoded parameters (WIP). Returns HTTP::Client::Response

Getters :

.token :
Myoauth2::Token
# struct Token
#   include JSON::Serializable
#   @access_token : String = String.new
#   @expires_in : Int32 = 0
#   @created_at : Int32 = 0
# end

        Returns the token object Myoauth2::Token

.token_expires_at :
Int64

        Returns the timestamp that the token will expire at.