Class: Rack::OAuth2::Server::OAuthRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/rack/oauth2/server.rb

Overview

Wraps Rack::Request to expose Basic and OAuth authentication credentials.

Constant Summary collapse

AUTHORIZATION_KEYS =
%w{HTTP_AUTHORIZATION X-HTTP_AUTHORIZATION X_HTTP_AUTHORIZATION}

Instance Method Summary collapse

Instance Method Details

#authorizationObject

Returns authorization header.



555
556
557
# File 'lib/rack/oauth2/server.rb', line 555

def authorization
  @authorization ||= AUTHORIZATION_KEYS.inject(nil) { |auth, key| auth || @env[key] }
end

#basic?Boolean

True if authentication scheme is Basic.

Returns:

  • (Boolean)


565
566
567
# File 'lib/rack/oauth2/server.rb', line 565

def basic?
  authorization[/^basic/i] if authorization
end

#credentialsObject

If Basic auth, returns username/password, if OAuth, returns access token.



571
572
573
574
# File 'lib/rack/oauth2/server.rb', line 571

def credentials
  basic? ? authorization.gsub(/\n/, "").split[1].unpack("m*").first.split(/:/, 2) :
  oauth? ? authorization.gsub(/\n/, "").split[1] : nil
end

#oauth?Boolean

True if authentication scheme is OAuth.

Returns:

  • (Boolean)


560
561
562
# File 'lib/rack/oauth2/server.rb', line 560

def oauth?
  authorization[/^oauth/i] if authorization
end