Class: Hitch::AuthorizationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Hitch::AuthorizationsController
- Includes:
- OauthFormAdmission
- Defined in:
- app/controllers/hitch/authorizations_controller.rb
Overview
GET /oauth/authorize — render consent screen POST /oauth/authorize — issue authorization code
Session-authenticated. Inherits the host's auth concern through Hitch::ApplicationController. If current_principal is nil, the controller redirects to Hitch.configuration.login_path (or returns 401 if unset).
RFC 8707 audience binding: the resource param sent by the client
is persisted on the access token at issue time and validated at
token-use time, satisfying the MCP authorization spec's audience MUST.
The flow's HTTP-free reasoning — parameter validation, client and redirect resolution, scope clamping, redirect construction — lives in Hitch::AuthorizationRequest; this controller renders its decisions.
Constant Summary collapse
- AUTHORIZATION_PARAMETER_NAMES =
%i[ response_type client_id redirect_uri scope state code_challenge code_challenge_method resource ].freeze
Constants included from RequestAdmission
RequestAdmission::MAX_REQUEST_BODY_BYTES
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/hitch/authorizations_controller.rb', line 63 def create return require_principal! unless current_principal = (*AUTHORIZATION_PARAMETER_NAMES, :decision) return () unless .valid? # RFC 6749 §4.1.2.1: the user declining is reported to the validated # redirect_uri as access_denied — with iss, like every redirect. if .deny? return redirect_to_client( .redirect_uri_for(error: "access_denied", state: .state) ) end token = Hitch::AccessToken.( principal: current_principal, client_id: .client_id, client_name: .audit_client_name, redirect_uri: .redirect_uri, code_challenge: .code_challenge, code_challenge_method: .code_challenge_method, resource_uri: .resource, scopes: .granted_scopes ) redirect_to_client( .redirect_uri_for(code: token., state: .state) ) end |
#new ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/hitch/authorizations_controller.rb', line 46 def new return require_principal! unless current_principal = (*AUTHORIZATION_PARAMETER_NAMES) return () unless .valid? @oauth_params = .params @redirect_host = .redirect_host @client_name = .display_client_name @brand_name = Hitch.configuration.brand_name @resource = .resource @localhost_only_client = .localhost_only_client? # Show the user exactly what they're approving (clamped to the # server allowlist — never echo an unsupported requested scope). @scopes = .granted_scopes end |