module Doorkeeper::OAuth::Token::Methods

def decode_basic_credentials(encoded_header)

def decode_basic_credentials(encoded_header)
  Base64.decode64(encoded_header).split(/:/, 2)
end

def from_access_token_param(request)

def from_access_token_param(request)
  request.parameters[:access_token]
end

def from_basic_authorization(request)

def from_basic_authorization(request)
  pattern = /^Basic /
  header  = request.authorization
  token_from_basic_header(header, pattern) if match?(header, pattern)
end

def from_bearer_authorization(request)

def from_bearer_authorization(request)
  pattern = /^Bearer /
  header  = request.authorization
  token_from_header(header, pattern) if match?(header, pattern)
end

def from_bearer_param(request)

def from_bearer_param(request)
  request.parameters[:bearer_token]
end

def match?(header, pattern)

def match?(header, pattern)
  header && header.match(pattern)
end

def token_from_basic_header(header, pattern)

def token_from_basic_header(header, pattern)
  encoded_header = token_from_header(header, pattern)
  token, _ = decode_basic_credentials(encoded_header)
  token
end

def token_from_header(header, pattern)

def token_from_header(header, pattern)
  header.gsub pattern, ''
end