module Revit::Auth
Convience module for handling our authentication actions and talking to
Auth0
@author [brwnrclse]
Constants
- AUTH_URL
- VERIFIER
Public Class Methods
auth_code_url()
click to toggle source
Provides the user with a means to obtain an authorization code for
accessing rev's api by opening a browser to our Auth0 login page
@return [nil]
# File lib/revit/auth.rb, line 33 def self.auth_code_url verifier_challenge = Sysrandom.urlsafe_base64( Digest::SHA256.new.update(VERIFIER).digest.to_i ) auth_code_url = AUTH_URL + '/authorize?response_type=code&scope=openid%20profile' \ '&client_id=' + AUTH_CLIENT_ID + '&redirect_uri=' + AUTH_CALLBACK_URL + '&code_challenge=' + verifier_challenge + '&code_challenge_method=S256' auth_code_url end
auth_token(auth_code)
click to toggle source
Exchanges the auth code obtained for a token used to access rev's api
@param auth_code [String]
@return [String]
# File lib/revit/auth.rb, line 54 def self.auth_token(auth_code) auth_token_uri = URI.parse('https://vaemoi.auth0.com/oauth/token') body = { grant_type: 'authorization_code', client_id: AUTH_CLIENT_ID, code_verifier: VERIFIER, code: auth_code, redirect_uri: AUTH_CALLBACK_URL } http = Net::HTTP.new(auth_token_uri.host, auth_token_uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(auth_token_uri) req.content_type = 'application/json' req.body = body.to_json res = http.request(req) body = JSON.parse(res.body) token = { access_token: body['access_token'], auth0_id: body['id_token'], expires: Time.now.to_i + body['expires'].to_i } token end
logged_in()
click to toggle source
Checks if the user has an Authentication token for accessing the API
@return [Bool] true if token found
raises an exception otherwise
# File lib/revit/auth.rb, line 89 def self.logged_in if AUTH_STORE_ACCESS_TOKEN.nil? || AUTH_STORE_ACCESS_TOKEN.empty? raise Revit::LoginException end true end