Exception: X::AuthorizationDenied

Inherits:
Error
  • Object
show all
Defined in:
x-core/lib/x/core/errors/authorization_denied.rb

Overview

Error raised when the redirect back from X reports that the app was not authorized

X redirects the user back to the app with an error, rather than a code, when the user declines to authorize the app, or when X cannot ask them, and the redirect is refused when its state does not match the one the app sent, or when it is not a valid URL. The redirect is a request of the user's browser, not a response of X, so the error holds no response, and descends from Error directly; a refusal of X to exchange the code raises AuthorizationError, a ClientError that holds the response of X.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, error_code: nil) ⇒ AuthorizationDenied

Initialize a new AuthorizationDenied

Examples:

Create an error

X::AuthorizationDenied.new("The user denied the request", error_code: "access_denied")

Raise the error with no message, as a test stub may

raise X::AuthorizationDenied

Parameters:

  • message (String, nil) (defaults to: nil) —

    the reason the app was not authorized, or nil for the name of the class, as an exception raised with no message is named

  • error_code (String, nil) (defaults to: nil) —

    the OAuth 2.0 error code, or nil for none



50
51
52
53
# File 'x-core/lib/x/core/errors/authorization_denied.rb', line 50

def initialize(message = nil, error_code: nil)
  super(message)
  @error_code = error_code
end

Instance Attribute Details

#error_code ⇒ String? (readonly)

The OAuth 2.0 error code the redirect reported, such as access_denied

Examples:

Tell a user who declined from a failure

rescue X::AuthorizationDenied => e
  redirect_to root_path if e.error_code.eql?("access_denied")

Returns:

  • (String, nil) —

    the error code, or nil for a redirect that reported none, as one whose state does not match reports none



23
24
25
# File 'x-core/lib/x/core/errors/authorization_denied.rb', line 23

def error_code
  @error_code
end