Class: BrowserID::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/browserid-provider/provider.rb

Overview

The BrowserID Provider Rack App

Default paths are:

GET  /users/sign_in
GET  /browserid/provision
GET  /browserid/whoami
POST /browserid/certify

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, options = {}) ⇒ Provider

Returns a new instance of Provider.



12
13
14
15
# File 'lib/browserid-provider/provider.rb', line 12

def initialize(app = nil, options = {})
  @app, @config = app, BrowserID::Config.new(options)
  @identity = BrowserID::Identity.new
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



10
11
12
# File 'lib/browserid-provider/provider.rb', line 10

def config
  @config
end

#envObject

Returns the value of attribute env.



10
11
12
# File 'lib/browserid-provider/provider.rb', line 10

def env
  @env
end

#identityObject

Returns the value of attribute identity.



10
11
12
# File 'lib/browserid-provider/provider.rb', line 10

def identity
  @identity
end

#reqObject

Returns the value of attribute req.



10
11
12
# File 'lib/browserid-provider/provider.rb', line 10

def req
  @req
end

Instance Method Details

#call(env) ⇒ Object

Rack enabled!



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/browserid-provider/provider.rb', line 18

def call(env)
  @env, @path = env, env["PATH_INFO"], @req = Rack::Request.new(env)
  env['browserid'] = @config

  # Return Not found or send call back to middleware stack unless the URL is captured here
  return (@app ? @app.call(env) : not_found) unless @config.urls.include? @path

  case @path
    when "/.well-known/browserid"
      @req.get? ? well_known_browserid : not_found
    when config.whoami_path
      @req.get? ? whoami : not_found
    when config.provision_path
      @req.get? ? provision : not_found
    when config.certify_path
      @req.post? ? certify : not_found
    else not_found
  end
end