class OauthService::Provider

Constants

AVAILABLE_PROVIDERS

Attributes

auth_url[R]
client_id[R]
client_secret[R]
downcase_name[R]
info_url[R]
name[R]
scopes[R]
token_url[R]

Public Class Methods

get_provider_by_name(name) click to toggle source
# File lib/oauth_service/provider.rb, line 77
def self.get_provider_by_name(name)
  res = providers_data.select do |provider|
    provider.downcase_name == name.downcase
  end
  
  res ? res.first : nil
end
new(name, downcase_name, auth_url, client_id, client_secret, info_url, scopes, token_url) click to toggle source
# File lib/oauth_service/provider.rb, line 9
def initialize(name, downcase_name, auth_url, client_id, client_secret,
  info_url, scopes, token_url)
  @name = name
  @downcase_name = downcase_name
  @auth_url = auth_url
  @client_id = client_id
  @client_secret = client_secret
  @info_url = info_url
  @scopes = scopes
  @token_url = token_url
end
providers_data() click to toggle source
# File lib/oauth_service/provider.rb, line 57
def self.providers_data
  @@providers_data ||= AVAILABLE_PROVIDERS.collect do |provider|
    ("OauthService::Provider::#{provider.downcase.camelize}").constantize.new(
      provider,
      provider.downcase,
      ENV["#{provider}_AUTH_URL"],
      ENV["#{provider}_CLIENT_ID"],
      ENV["#{provider}_CLIENT_SECRET"],
      ENV["#{provider}_INFO_URL"],
      ENV["#{provider}_SCOPES"],
      ENV["#{provider}_TOKEN_URL"]
    ) if ENV["#{provider}_AUTH_URL"] &&
      ENV["#{provider}_CLIENT_ID"] &&
      ENV["#{provider}_CLIENT_SECRET"] &&
      ENV["#{provider}_INFO_URL"] &&
      ENV["#{provider}_SCOPES"] &&
      ENV["#{provider}_TOKEN_URL"]
  end.compact
end

Public Instance Methods

get_info_headers(options = {}) click to toggle source
# File lib/oauth_service/provider.rb, line 49
def get_info_headers(options = {})
  raise "Headers for token request method is undefined"
end
get_info_params(options = {}) click to toggle source
# File lib/oauth_service/provider.rb, line 53
def get_info_params(options = {})
  raise "Paramaters for information request method is undefined"
end
get_redirect_uri(request_url) click to toggle source
# File lib/oauth_service/provider.rb, line 21
def get_redirect_uri(request_url)
  redirect_uri  = OauthService.redirect_uri

  if redirect_uri[0..3]=="http"
    redirect_uri + downcase_name
  else
    uri = URI.parse(request_url)
    uri.path = redirect_uri + downcase_name
    uri.query = nil
    
    return uri.to_s
  end
end
get_token_params(options = {}) click to toggle source
# File lib/oauth_service/provider.rb, line 35
def get_token_params(options = {})
  {
    'client_id' => client_id,
    'client_secret' => client_secret,
    'redirect_uri' => get_redirect_uri(options[:original_url]),
    'grant_type' => 'authorization_code',
    'code' => options[:code]
  }
end
get_user_info(info) click to toggle source
# File lib/oauth_service/provider.rb, line 45
def get_user_info(info)
  info
end