Module: Authlete::Utility

Instance Method Summary collapse

Instance Method Details

#extract_access_token(request) ⇒ Object

Extract an access token (RFC 6750)



21
22
23
24
25
26
27
28
29
# File 'lib/authlete/utility.rb', line 21

def extract_access_token(request)
  header = request.env['HTTP_AUTHORIZATION']

  if /^Bearer[ ]+(.+)/i =~ header
    return $1
  end

  request['access_token']
end

#get_parsed_array(array) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/authlete/utility.rb', line 31

def get_parsed_array(array)
  return nil if !array.kind_of?(Array) or array.empty?

  elements = []

  array.each do |element|
    parsed_element = yield(element)
    elements.push(parsed_element) unless parsed_element.nil?
  end

  elements.empty? ? nil : elements
end

#to_rack_response_json(status_code, content) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/authlete/utility.rb', line 44

def to_rack_response_json(status_code, content)
  [
    status_code,
    {
      'Content-Type'  => 'application/json;charset=UTF-8',
      'Cache-Control' => 'no-store',
      'Pragma'        => 'no-cache'
    },
    [
      content
    ]
  ]
end

#to_rack_response_www_authenticate(status_code, content) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/authlete/utility.rb', line 58

def to_rack_response_www_authenticate(status_code, content)
  [
    status_code,
    {
      'WWW-Authenticate' => content,
      'Cache-Control'    => 'no-store',
      'Pragma'           => 'no-cache'
    },
    nil
  ]
end