Class: JSONRPC2::BasicAuth

Inherits:
HttpAuth show all
Defined in:
lib/jsonrpc2/auth.rb

Overview

HTTP Basic authentication implementation

Instance Method Summary collapse

Methods inherited from Auth

#inspect

Constructor Details

#initialize(users = nil) {|user, pass| ... } ⇒ BasicAuth

Create a BasicAuth object

Parameters:

  • users (Hash<String,String>) (defaults to: nil)

    containing containing usernames and passwords

Yields:

  • (user, pass)

    Username and password to authenticate

Yield Returns:

  • (Boolean)

    True if credentials are approved



56
57
58
# File 'lib/jsonrpc2/auth.rb', line 56

def initialize(users=nil, &block)
  @users, @lookup = users, block
end

Instance Method Details

#browser_check(env) ⇒ true

Checks that the browser is authorised to access the API (used by HTML API introspection)

Parameters:

  • env (Hash, Rack::Request)

    Rack environment hash

Returns:

  • (true)

    Returns true or throws :rack_response, [ 401, … ]



73
74
75
# File 'lib/jsonrpc2/auth.rb', line 73

def browser_check(env)
  valid?(env) or throw_401
end

#client_check(env, rpc) ⇒ true

Checks that the client is authorised to access the API

Parameters:

  • env (Hash, Rack::Request)

    Rack environment hash

  • rpc (Hash)

    JSON-RPC2 call content

Returns:

  • (true)

    Returns true or throws :rack_response, [ 401, … ]



65
66
67
# File 'lib/jsonrpc2/auth.rb', line 65

def client_check(env, rpc)
  browser_check(env)
end