Class: OAuth2::MCP::ScopeMapper
- Inherits:
-
Object
- Object
- OAuth2::MCP::ScopeMapper
- Defined in:
- lib/oauth2/mcp.rb
Overview
Maps validated OAuth scopes into application capabilities.
Instance Attribute Summary collapse
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
Instance Method Summary collapse
-
#capabilities_for(claims_or_scopes) ⇒ Object
-
#initialize(mapping:, passthrough: false) ⇒ ScopeMapper
constructor
A new instance of ScopeMapper.
Constructor Details
#initialize(mapping:, passthrough: false) ⇒ ScopeMapper
Returns a new instance of ScopeMapper.
109 110 111 112 113 |
# File 'lib/oauth2/mcp.rb', line 109 def initialize(mapping:, passthrough: false) @mapping = normalize_mapping(mapping) @passthrough = passthrough raise ConfigurationError, "scope mapping must not be empty" if @mapping.empty? && !@passthrough end |
Instance Attribute Details
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
107 108 109 |
# File 'lib/oauth2/mcp.rb', line 107 def mapping @mapping end |
Instance Method Details
#capabilities_for(claims_or_scopes) ⇒ Object
115 116 117 118 |
# File 'lib/oauth2/mcp.rb', line 115 def capabilities_for(claims_or_scopes) scopes = claims_or_scopes.respond_to?(:scopes) ? claims_or_scopes.scopes : claims_or_scopes Array(scopes).flat_map { |scope| capabilities_for_scope(scope) }.uniq.freeze end |