Class: Fakturoid::Oauth::Flow::AuthorizationCode

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/fakturoid/oauth/flow/authorization_code.rb

Constant Summary collapse

GRANT_TYPE =
"authorization_code"

Instance Attribute Summary

Attributes included from Base

#client

Instance Method Summary collapse

Methods included from Base

#initialize

Instance Method Details

#authorization_uri(state: nil) ⇒ Object



11
12
13
# File 'lib/fakturoid/oauth/flow/authorization_code.rb', line 11

def authorization_uri(state: nil)
  client.config.authorization_uri(state: state)
end

#authorize(code:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fakturoid/oauth/flow/authorization_code.rb', line 15

def authorize(code:)
  payload = {
    grant_type: GRANT_TYPE,
    redirect_uri: client.config.redirect_uri,
    code: code
  }

  response = perform_request(HTTP_POST, "token.json", payload: payload)
  client.config.credentials.update(response.body)
  client.call_credentials_updated_callback
  response
end

#authorized?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/fakturoid/oauth/flow/authorization_code.rb', line 47

def authorized?
  !Utils.empty?(client.config.credentials.refresh_token)
end

#fetch_access_tokenObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/fakturoid/oauth/flow/authorization_code.rb', line 28

def fetch_access_token
  payload = {
    grant_type: "refresh_token",
    refresh_token: client.config.credentials.refresh_token
  }

  response = perform_request(HTTP_POST, "token.json", payload: payload)
  client.config.credentials.update(response.body)
  response
end

#revoke_accessObject



39
40
41
42
43
44
45
# File 'lib/fakturoid/oauth/flow/authorization_code.rb', line 39

def revoke_access
  payload = {
    token: client.config.credentials.refresh_token
  }

  perform_request(HTTP_POST, "revoke.json", payload: payload)
end