Module: Ecoportal::API::Common::GraphQL::AuthService::InstanceMethods

Included in:
Ecoportal::API::Common::GraphQL::AuthService
Defined in:
lib/ecoportal/api/common/graphql/auth_service.rb

Instance Method Summary collapse

Instance Method Details

#session_token(host: server, version: nil, auto_renew: true) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ecoportal/api/common/graphql/auth_service.rb', line 10

def session_token(host: server, version: nil, auto_renew: true)
  session_token_data(host: host, version: version).then do |body|
    next unless body

    if auto_renew && token_renew?(body['expires_in'])
      session_token_renewed(
        host:          host,
        version:       version,
        refresh_token: body['refresh_token']
      )
    else
      body['access_token']
    end
  end
end

#session_token_renewed(host: server, version: nil, refresh_token: nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ecoportal/api/common/graphql/auth_service.rb', line 26

def session_token_renewed(host: server, version: nil, refresh_token: nil)
  unless refresh_token
    return unless (body = session_token_data(host: host, version: version))
    return unless (refresh_token = body['resfresh_token'])
  end

  session_refresh_token_data(
    host:          host,
    version:       version,
    refresh_token: refresh_token
  ).then do |bdy|
    bdy['access_token'] if bdy
  end
end