# signet - Class Signet::OAuth1::Server (v0.22.0)

0.22.0 (latest) 0.21.0 0.20.0 Reference documentation and code samples for the signet class Signet::OAuth1::Server.

## Inherits

- Object

## Methods

### #authenticate_resource_request

    def authenticate_resource_request(options) -> Hash

Authenticates a request for a protected resource.
**Overloads**

    def authenticate_resource_request(options) -> Hash

Authenticates a request for a protected resource. **Parameters**

- **request** (Hash) --- The configuration parameters for the request.
- **method** (String) --- the HTTP method , defaults to `GET`
- **uri** (Addressable::URI, String) --- the URI .
- **headers** (Hash, Array) --- the HTTP headers.
- **body** (StringIO, String) --- The HTTP body.
- **two_legged** (Boolean) --- skip the token_credential lookup?
- **adapter** (HTTPAdapter) --- The HTTP adapter(optional).
**Returns**

- (Hash) --- A hash of the credentials and realm for a valid request, or `nil` if not valid.
**Raises**

- (TypeError)

### #authenticate_temporary_credential_request

    def authenticate_temporary_credential_request(options) -> String

Authenticates a temporary credential request. If no oauth_callback is
present in the request, `oob` will be returned.
**Overloads**

    def authenticate_temporary_credential_request(options) -> String

Authenticates a temporary credential request. If no oauth_callback is present in the request, `oob` will be returned. **Parameters**

- **request** (Hash) --- The configuration parameters for the request.
- **method** (String) --- the HTTP method , defaults to `GET`
- **uri** (Addressable::URI, String) --- the URI .
- **headers** (Hash, Array) --- the HTTP headers.
- **body** (StringIO, String) --- The HTTP body.
- **adapter** (HTTPAdapter) --- The HTTP adapter(optional).
**Returns**

- (String) --- The oauth_callback value, or `false` if not valid.

### #authenticate_token_credential_request

    def authenticate_token_credential_request(options) -> Hash

Authenticates a token credential request.
**Overloads**

    def authenticate_token_credential_request(options) -> Hash

Authenticates a token credential request. **Parameters**

- **request** (Hash) --- The configuration parameters for the request.
- **method** (String) --- the HTTP method , defaults to `GET`
- **uri** (Addressable::URI, String) --- the URI .
- **headers** (Hash, Array) --- the HTTP headers.
- **body** (StringIO, String) --- The HTTP body.
- **adapter** (HTTPAdapter) --- The HTTP adapter(optional).
**Returns**

- (Hash) --- A hash of credentials and realm for a valid request, or `nil` if not valid.

### #call_credential_lookup

    def call_credential_lookup(credential, key) -> Signet::OAuth1::Credential

Call a credential lookup, and cast the result to a proper Credential.
**Parameters**

- **credential** (Proc) --- to call.
- **key** (String) --- provided to the Proc in `credential`
**Returns**

- ([Signet::OAuth1::Credential](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Credential)) --- credential provided by `credential` (if any).

### #client_credential

    def client_credential() -> Proc

**Returns**

- (Proc) --- lookup the value from this Proc.

### #client_credential=

    def client_credential=(value) -> Proc

**Parameter**

- **value** (Proc) --- lookup the value from this Proc.
**Returns**

- (Proc) --- lookup the value from this Proc.

### #find_client_credential

    def find_client_credential(key) -> Signet::OAuth1::Credential

Find the appropriate client credential by calling
the [#client_credential](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Server#Signet__OAuth1__Server_client_credential_instance_ "Signet::OAuth1::Server#client_credential (method)") Proc.
**Parameter**

- **key** (String) --- provided to the [#client_credential](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Server#Signet__OAuth1__Server_client_credential_instance_ "Signet::OAuth1::Server#client_credential (method)") Proc.
**Returns**

- ([Signet::OAuth1::Credential](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Credential)) --- The client credential.

### #find_temporary_credential

    def find_temporary_credential(key) -> Signet::OAuth1::Credential

Find the appropriate client credential by calling
the [#temporary_credential](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Server#Signet__OAuth1__Server_temporary_credential_instance_ "Signet::OAuth1::Server#temporary_credential (method)") Proc.
**Parameter**

- **key** (String) --- provided to the [#temporary_credential](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Server#Signet__OAuth1__Server_temporary_credential_instance_ "Signet::OAuth1::Server#temporary_credential (method)") Proc.
**Returns**

- ([Signet::OAuth1::Credential](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Credential)) --- if the credential is found.

### #find_token_credential

    def find_token_credential(key) -> Signet::OAuth1::Credential

Find the appropriate client credential by calling
the [#token_credential](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Server#Signet__OAuth1__Server_token_credential_instance_ "Signet::OAuth1::Server#token_credential (method)") Proc.
**Parameter**

- **key** (String) --- provided to the [#token_credential](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Server#Signet__OAuth1__Server_token_credential_instance_ "Signet::OAuth1::Server#token_credential (method)") Proc.
**Returns**

- ([Signet::OAuth1::Credential](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Credential)) --- if the credential is found.

### #find_verifier

    def find_verifier(verifier) -> Boolean

Determine if the verifier is valid by calling the Proc in [#verifier](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Server#Signet__OAuth1__Server_verifier_instance_ "Signet::OAuth1::Server#verifier (method)").
**Parameter**

- **verifier** (String) --- Key provided to the [#verifier](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Server#Signet__OAuth1__Server_verifier_instance_ "Signet::OAuth1::Server#verifier (method)") Proc.
**Returns**

- (Boolean) --- if the verifier Proc returns anything other than `nil` or `false`

### #initialize

    def initialize(options) -> Server

Creates an OAuth 1.0 server.
**Overloads**

    def initialize(options) -> Server

Creates an OAuth 1.0 server. **Parameters**

- **nonce_timestamp** (Proc) --- verify a nonce/timestamp pair.
- **client_credential** (Proc) --- find a client credential.
- **token_credential** (Proc) --- find a token credential.
- **temporary_credential** (Proc) --- find a temporary credential.
- **verifier** (Proc) --- validate a verifier value.
**Returns**

- ([Server](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Server)) --- a new instance of Server
**Example**

```ruby
server = Signet::OAuth1::Server.new(
  :nonce_timestamp =>
    lambda { |n,t| OauthNonce.remember(n,t) },
  :client_credential =>
    lambda { |key| ClientCredential.find_by_key(key).to_hash },
  :token_credential =>
    lambda { |key| TokenCredential.find_by_key(key).to_hash },
  :temporary_credential =>
    lambda { |key| TemporaryCredential.find_by_key(key).to_hash },
  :verifier =>
    lambda {|verifier| Verifier.find_by_verifier(verifier).active? }
)
```

### #nonce_timestamp

    def nonce_timestamp() -> Proc

**Returns**

- (Proc) --- lookup the value from this Proc.

### #nonce_timestamp=

    def nonce_timestamp=(value) -> Proc

**Parameter**

- **value** (Proc) --- lookup the value from this Proc.
**Returns**

- (Proc) --- lookup the value from this Proc.

### #request_realm

    def request_realm(options) -> String

**Overloads**

    def request_realm(options) -> String

**Parameters**

- **request** (Hash) --- A pre-constructed request to verify.
- **method** (String) --- the HTTP method , defaults to `GET`
- **uri** (Addressable::URI, String) --- the URI .
- **headers** (Hash, Array) --- the HTTP headers.
- **body** (StringIO, String) --- The HTTP body.
- **adapter** (HTTPAdapter) --- The HTTP adapter(optional).
**Returns**

- (String) --- The Authorization realm(see RFC 2617) of the request.
**Raises**

- ([MalformedAuthorizationError](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-MalformedAuthorizationError))

### #safe_equals?

    def safe_equals?(left, right) -> Boolean

Constant time string comparison.
**Returns**

- (Boolean)

### #temporary_credential

    def temporary_credential() -> Proc

**Returns**

- (Proc) --- lookup the value from this Proc.

### #temporary_credential=

    def temporary_credential=(value) -> Proc

**Parameter**

- **value** (Proc) --- lookup the value from this Proc.
**Returns**

- (Proc) --- lookup the value from this Proc.

### #token_credential

    def token_credential() -> Proc

**Returns**

- (Proc) --- lookup the value from this Proc.

### #token_credential=

    def token_credential=(value) -> Proc

**Parameter**

- **value** (Proc) --- lookup the value from this Proc.
**Returns**

- (Proc) --- lookup the value from this Proc.

### #validate_nonce_timestamp

    def validate_nonce_timestamp(nonce, timestamp) -> Boolean

Determine if the supplied nonce/timestamp pair is valid by calling
the [#nonce_timestamp](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-OAuth1-Server#Signet__OAuth1__Server_nonce_timestamp_instance_ "Signet::OAuth1::Server#nonce_timestamp (method)") Proc.
**Parameters**

- **nonce** (String, #to_str) --- value from the request
- **timestamp** (String, #to_str) --- value from the request
**Returns**

- (Boolean) --- if the nonce/timestamp pair is valid.

### #verifier

    def verifier() -> Proc

**Returns**

- (Proc) --- lookup the value from this Proc.

### #verifier=

    def verifier=(value) -> Proc

**Parameter**

- **value** (Proc) --- lookup the value from this Proc.
**Returns**

- (Proc) --- lookup the value from this Proc.

### #verify_auth_header_components

    def verify_auth_header_components(headers) -> Hash

Validate and normalize the HTTP Authorization header.
**Parameter**

- **headers** (Array) --- from HTTP request.
**Returns**

- (Hash) --- Hash of Authorization header.
**Raises**

- ([MalformedAuthorizationError](https://docs.cloud.google.com/ruby/docs/reference/signet/latest/Signet-MalformedAuthorizationError))

### #verify_request_components

    def verify_request_components(options) -> Hash

Validate and normalize the components from an HTTP request.
**Overloads**

    def verify_request_components(options) -> Hash

Validate and normalize the components from an HTTP request. **Parameters**

- **request** (Faraday::Request) --- A pre-constructed request to verify.
- **method** (String) --- the HTTP method , defaults to `GET`
- **uri** (Addressable::URI, String) --- the URI .
- **headers** (Hash, Array) --- the HTTP headers.
- **body** (StringIO, String) --- The HTTP body.
- **adapter** (HTTPAdapter) --- The HTTP adapter(optional).
**Returns**

- (Hash) --- normalized request components