Module: MyobAcumatica::OAuth2::Token
- Defined in:
- lib/myob_acumatica/o_auth_2/token.rb
Overview
Handles the OAuth2 flow for authenticating with MYOB Acumatica.
Class Method Summary collapse
-
.authorize(code:, redirect_uri: REDIRECT_URI, instance_name: INSTANCE_NAME, client_id: CLIENT_ID, client_secret: CLIENT_SECRET, logger: nil) ⇒ Hash
Exchanges an authorization code for an access token.
-
.authorize_url(redirect_uri: REDIRECT_URI, instance_name: INSTANCE_NAME, client_id: CLIENT_ID, scope: SCOPE) ⇒ String
Generates the OAuth2 authorization URL to initiate the login flow.
-
.refresh(refresh_token:, instance_name: INSTANCE_NAME, client_id: CLIENT_ID, client_secret: CLIENT_SECRET, logger: nil) ⇒ Hash
Refreshes the access token using a refresh token.
Class Method Details
.authorize(code:, redirect_uri: REDIRECT_URI, instance_name: INSTANCE_NAME, client_id: CLIENT_ID, client_secret: CLIENT_SECRET, logger: nil) ⇒ Hash
Exchanges an authorization code for an access token.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/myob_acumatica/o_auth_2/token.rb', line 60 def ( code:, redirect_uri: REDIRECT_URI, instance_name: INSTANCE_NAME, client_id: CLIENT_ID, client_secret: CLIENT_SECRET, logger: nil ) Http.post( uri: URI("https://#{instance_name}/identity/connect/token"), body: { grant_type: 'authorization_code', client_id: client_id, client_secret: client_secret, code: code, redirect_uri: redirect_uri }, logger: logger ) end |
.authorize_url(redirect_uri: REDIRECT_URI, instance_name: INSTANCE_NAME, client_id: CLIENT_ID, scope: SCOPE) ⇒ String
Generates the OAuth2 authorization URL to initiate the login flow.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/myob_acumatica/o_auth_2/token.rb', line 25 def ( redirect_uri: REDIRECT_URI, instance_name: INSTANCE_NAME, client_id: CLIENT_ID, scope: SCOPE ) "https://#{instance_name}/identity/connect/authorize?" \ "#{URI.encode_www_form({ response_type: 'code', client_id: client_id, redirect_uri: redirect_uri, scope: scope })}" end |
.refresh(refresh_token:, instance_name: INSTANCE_NAME, client_id: CLIENT_ID, client_secret: CLIENT_SECRET, logger: nil) ⇒ Hash
Refreshes the access token using a refresh token.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/myob_acumatica/o_auth_2/token.rb', line 99 def refresh( refresh_token:, instance_name: INSTANCE_NAME, client_id: CLIENT_ID, client_secret: CLIENT_SECRET, logger: nil ) Http.post( uri: URI("https://#{instance_name}/identity/connect/token"), body: { grant_type: 'refresh_token', client_id: client_id, client_secret: client_secret, refresh_token: refresh_token }, logger: logger ) end |