Module: Octokit::Client::Tokens

Included in:
Octokit::Client
Defined in:
lib/octokit/client/tokens.rb

Overview

Method to check scopes

Instance Method Summary collapse

Instance Method Details

#scopes(token = @access_token, options = {}) ⇒ Array<String>

Check scopes for a token

Parameters:

  • token (String) (defaults to: @access_token)

    GitHub OAuth token

  • options (Hash) (defaults to: {})

    Header params for request

Returns:

  • (Array<String>)

    OAuth scopes

Raises:

  • (ArgumentError)

See Also:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/octokit/client/tokens.rb', line 15

def scopes(token = @access_token, options = {})
  options = options.dup
  raise ArgumentError, 'Access token required' if token.nil?

  auth = { 'Authorization' => "token #{token}" }
  headers = (options.delete(:headers) || {}).merge(auth)

  agent.call(:get, 'user', headers: headers)
       .headers['X-OAuth-Scopes']
       .to_s
       .split(',')
       .map(&:strip)
       .sort
end