croauth2

An oauth2 module in crystal

An oauth2 module in crystal

Requirement :

  • crystal >= 0.27.2

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.

Repository

croauth2

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 1
  • over 5 years ago
  • March 25, 2019
License

GNU General Public License v3.0

Links
Synced at

Fri, 08 Nov 2024 01:28:57 GMT

Languages