Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The resource_owner.attributes field used by filter_scopes is not a Hash #77

Open
IcarusCoding opened this issue Sep 25, 2023 · 0 comments

Comments

@IcarusCoding
Copy link

The current filter_scopes function execution results in a HTTP 500 when the /consent endpoint is called.
I am not sure if that is caused by a configuration error on my side though.

def filter_scopes(resource_owner, client, scopes)
  scope_mapping = Config.read_config CONFIG_SECTION_SCOPE_MAPPING, {}
  ((scopes || []) & [*client.metadata['scope']]).select do |s|
    if s == 'openid'
      true
    elsif s.include? ':'
      key, value = s.split(':', 2)
      av = resource_owner.attributes[key] # <--  resource_owner.attributes.class is not a Hash; indexing with a String
      av = { 'value' => av } unless av.instance_of?(Hash)
      av && av['value'] == value
    else
      (scope_mapping[s] || []).any? { |claim| resource_owner.attributes[claim] }
    end
  end
end

users.yml:

---
- username: admin
  attributes:
  - key: omejdn
    value: admin
  password: "$2a$12$At/un58ws8tY7VCAyvC0zulZIwNRC.rHvUGmpOc58yhMQawBbYrvG" # password
  backend: yaml

clients.yml:

---
- client_id: adminUI
  client_name: Omejdn Admin UI
  client_uri: http://localhost:4200
  logo_uri: http://localhost:4200/assets/img/fhg.jpg
  grant_types:
    - authorization_code
  software_id: Omejdn Admin UI
  software_version: 0.0.0
  token_endpoint_auth_method: none
  redirect_uris: http://localhost:4200
  post_logout_redirect_uris: http://localhost:4200
  scope:
    - openid
    - omejdn:write
    - omejdn:admin
    - omejdn:read
  attributes: []

My proposed change Fork:

     elsif s.include? ':'
       key, value = s.split(':', 2)
-      av = resource_owner.attributes[key]
+      av = resource_owner.attributes.find { |hash| hash['key'] == key }
       av = { 'value' => av } unless av.instance_of?(Hash)
       av && av['value'] == value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant