Class: Houston::Extensions::Oauth

Inherits:
Object
  • Object
show all
Defined in:
lib/houston/boot/extensions/oauth.rb

Defined Under Namespace

Classes: ProviderDsl, ProviderNotFound

Instance Method Summary collapse

Constructor Details

#initializeOauth

Returns a new instance of Oauth.



8
9
10
# File 'lib/houston/boot/extensions/oauth.rb', line 8

def initialize
  reset!
end

Instance Method Details

#add_provider(name, &block) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
# File 'lib/houston/boot/extensions/oauth.rb', line 20

def add_provider(name, &block)
  provider = Houston::Provider.new(name.to_sym)
  ProviderDsl.new(provider).instance_eval(&block)

  raise ArgumentError, "Provider must define a site" if provider.site.blank?
  raise ArgumentError, "Provider must define a authorize_path" if provider.authorize_path.blank?
  raise ArgumentError, "Provider must define a token_path" if provider.token_path.blank?

  @providers[provider.name] = provider
end

#get_provider(name) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/houston/boot/extensions/oauth.rb', line 31

def get_provider(name)
  name = name.to_sym
  @providers.fetch(name)
rescue KeyError
  puts "registered providers: #{providers.inspect}"
  raise ProviderNotFound, "An Oauth Provider named #{name.inspect} has not been registered"
end

#providersObject



16
17
18
# File 'lib/houston/boot/extensions/oauth.rb', line 16

def providers
  @providers.keys
end

#reset!Object



12
13
14
# File 'lib/houston/boot/extensions/oauth.rb', line 12

def reset!
  @providers = Concurrent::Hash.new
end