Class: OAuth2::MCP::ScopeMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2/mcp.rb

Overview

Maps validated OAuth scopes into application capabilities.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapping:, passthrough: false) ⇒ ScopeMapper

Returns a new instance of ScopeMapper.

Raises:



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

#mappingObject (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