Class: AuthArmor::Client
- Inherits:
-
Object
- Object
- AuthArmor::Client
- Defined in:
- lib/auth_armor.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#invite_code ⇒ Object
Returns the value of attribute invite_code.
Instance Method Summary collapse
- #auth_request(longitude: nil, latitude: nil, nonce: nil, timeout_in_seconds: nil, forcebiometric: false, accepted_auth_methods: nil, nickname:, action_name:, short_msg:) ⇒ Object
- #connect(payload: {}, method:, endpoint:) ⇒ Object
- #generate_qr_code ⇒ Object
- #get_invite_link ⇒ Object
-
#initialize(scope: "aarmor.api.generate_invite_code aarmor.api.request_auth", client_id:, client_secret:) ⇒ Client
constructor
A new instance of Client.
- #invite_request(reference_id: nil, reset_and_reinvite: false, nickname:) ⇒ Object
Constructor Details
#initialize(scope: "aarmor.api.generate_invite_code aarmor.api.request_auth", client_id:, client_secret:) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/auth_armor.rb', line 20 def initialize(scope: "aarmor.api.generate_invite_code aarmor.api.request_auth", client_id: , client_secret:) fail "Scope not allowed." unless ACCEPTED_SCOPES.include? scope payload = { client_id: client_id, client_secret: client_secret, grant_type: "client_credentials", scope: scope } response = RestClient.post("https://login.autharmor.com/connect/token", payload) if response.code == 200 @access_token = JSON.parse(response)["access_token"] else fail "Invalid response #{response.to_str} received." end end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
18 19 20 |
# File 'lib/auth_armor.rb', line 18 def access_token @access_token end |
#invite_code ⇒ Object
Returns the value of attribute invite_code.
18 19 20 |
# File 'lib/auth_armor.rb', line 18 def invite_code @invite_code end |
Instance Method Details
#auth_request(longitude: nil, latitude: nil, nonce: nil, timeout_in_seconds: nil, forcebiometric: false, accepted_auth_methods: nil, nickname:, action_name:, short_msg:) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/auth_armor.rb', line 60 def auth_request(longitude: nil, latitude: nil, nonce: nil, timeout_in_seconds: nil, forcebiometric: false, accepted_auth_methods: nil, nickname:, action_name:, short_msg:) payload = { nickname: nickname, action_name: action_name, short_msg: short_msg, timeout_in_seconds: timeout_in_seconds, nonce: nonce, accepted_auth_methods: auth_methods(accepted_auth_methods, forcebiometric), origin_location_data: { longitude: longitude, latitude: latitude } } connect(payload: payload, method: :post, endpoint: "auth/request") end |
#connect(payload: {}, method:, endpoint:) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/auth_armor.rb', line 39 def connect(payload: {}, method:, endpoint:) RestClient.post("#{API_URL}/#{endpoint}", payload.to_json, { content_type: 'application/json', Authorization: "Bearer #{@access_token}" }) do |response, request, result| case response.code when 400 { code: :error, response: JSON.parse(response.to_str) } when 200 { "code" => :success, "response" => JSON.parse(response.to_str) } else fail "Invalid response #{response.to_str} received." end end rescue RestClient::Unauthorized, RestClient::Forbidden => err JSON.parse(err.response.to_str) end |
#generate_qr_code ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/auth_armor.rb', line 95 def generate_qr_code fail "QR code could not be generated. Use the invite_request method to get an invite code" if @invite_code.nil? aa_sig = @invite_code["aa_sig"] invite_code = @invite_code["invite_code"] { "type": "profile_invite", "version": 1, "format_id": 1, "payload": { "aa_sig": aa_sig, "invite_code": invite_code } } end |
#get_invite_link ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/auth_armor.rb', line 113 def get_invite_link fail "Invite link could not be generated. Use the invite_request method to get an invite code" if @invite_code.nil? aa_sig = @invite_code["aa_sig"] invite_code = @invite_code["invite_code"] "#{INVITE_URL}/?i=#{invite_code}&aa_sig=#{aa_sig}" end |
#invite_request(reference_id: nil, reset_and_reinvite: false, nickname:) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/auth_armor.rb', line 77 def invite_request(reference_id: nil, reset_and_reinvite: false, nickname:) payload = { nickname: nickname, reference_id: reference_id, reset_and_reinvite: reset_and_reinvite } response = connect(payload: payload, method: :post, endpoint: "invite/request") if response["code"] == :success @invite_code = response["response"] else @invite_code = nil end response end |