network icon indicating copy to clipboard operation
network copied to clipboard

Getting Groups claims via OIDC

Open mounirmesselmeni opened this issue 2 years ago • 2 comments

Preflight checklist

Describe your problem

I’m trying the Ory cloud to make more progress with the auth flow, I’m using OIDC with Ory but I’m struggling to get the user’s groups memberships with the userinfo results. Now I’m getting this despite adding (group or groups to the requested scopes)

{
    "amr": [
        "password"
    ],
    "aud": [
        "xxxxxx-4dc9-8094-7d4926d3350e"
    ],
    "auth_time": 1678204037,
    "email": "[email protected]",
    "email_verified": true,
    "iat": 1678204043,
    "iss": "https: //pedantic-kilby-s9jc724ku9.projects.oryapis.com",
    "rat": 1678204033,
    "sub": "zxxxxxxx-d186-4251-8369-xxxxxxx"
}

Those are the relationships defined in the UI (I set them using the CLI) I’m using the default permissions modelling/rules:

import { Namespace, SubjectSet, Context } from "@ory/permission-namespace-types"

/*
Define your OPL rules here. Some examples:
*/
class User implements Namespace {
  related: {
    manager: User[]
  }
}

class Group implements Namespace {
  related: {
    members: (User | Group)[]
  }
}

class Folder implements Namespace {
  related: {
    parents: (File | Folder)[]
    viewers: SubjectSet<Group, "members">[]
  }

  permits = {
    view: (ctx: Context): boolean =>
      this.related.viewers.includes(ctx.subject) ||
      this.related.parents.traverse((p) => p.permits.view(ctx)),
  }
}

class File implements Namespace {
  related: {
    parents: (File | Folder)[]
    viewers: (User | SubjectSet<Group, "members">)[]
    owners: (User | SubjectSet<Group, "members">)[]
  }

  permits = {
    view: (ctx: Context): boolean =>
      this.related.parents.traverse((p) => p.permits.view(ctx)) ||
      this.related.viewers.includes(ctx.subject) ||
      this.related.owners.includes(ctx.subject),

    edit: (ctx: Context) => this.related.owners.includes(ctx.subject),
  }
}

thanks in advance

Describe your ideal solution

Getting the groups the user is membership on

Workarounds or alternatives

Nothing found yet as a workaround

Version

lastest // using cloud solution

Additional Context

No response

mounirmesselmeni avatar Mar 08 '23 12:03 mounirmesselmeni

This is kinda related to #261 but instead of traits we want to add certain relationships.

zepatrik avatar Mar 08 '23 12:03 zepatrik

@mounirmesselmeni thank you for the report! Unfortunately, the data from Ory Keto does not automatically populate into the ID token. I think that's a great idea though, I'm just not fully sure yet how that could work.

To populate the ID token with any data you want, you can write a custom consent endpoint. A guide for that is here: https://www.ory.sh/docs/hydra/guides/custom-ui-oauth2

You won't need to customize the login endpoint, only the consent endpoint. Using a custom consent endpoint, you can basically say what data goes into your tokens.

Hope this helps!

aeneasr avatar Jun 17 '23 08:06 aeneasr