Module: Authkeeper::YandexAuthApi::Requests::AccessToken

Included in:
Client
Defined in:
app/lib/authkeeper/yandex_auth_api/requests/access_token.rb

Instance Method Summary collapse

Instance Method Details

#fetch_access_token(client_id:, client_secret:, code:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/lib/authkeeper/yandex_auth_api/requests/access_token.rb', line 10

def fetch_access_token(client_id:, client_secret:, code:)
  post(
    path: 'token',
    body: URI.encode_www_form({
      grant_type: 'authorization_code',
      client_id: client_id,
      client_secret: client_secret,
      code: code
    }),
    headers: {
      'Content-Type' => 'application/x-www-form-urlencoded'
    }
  )
end

#refresh_access_token(client_id:, client_secret:, refresh_token:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/lib/authkeeper/yandex_auth_api/requests/access_token.rb', line 25

def refresh_access_token(client_id:, client_secret:, refresh_token:)
  post(
    path: 'token',
    body: URI.encode_www_form({
      grant_type: 'refresh_token',
      refresh_token: refresh_token
    }),
    headers: {
      'Content-Type' => 'application/x-www-form-urlencoded',
      'Authorization' => "Basic #{authorization(client_id, client_secret)}"
    }
  )
end