HNeukermans / adal-ts

Adal.js typescript rewrite
MIT License
38 stars 21 forks source link

Add roles #33

Closed evnexus closed 6 years ago

evnexus commented 7 years ago

I've been asked to implement an Angular 2 application with O365 Auth and roles. So, I've modified the manifest file on AD so i've that one done. I could obviously make it all on my API, but that would mean more calls, but I see that adal-ts has a potential to have an extra property role at the user.ts class.

EDIT - By that I mean: Represents all application roles that the subject has been granted both directly and indirectly through group membership and can be used to enforce role-based access control. Application roles are defined on a per-application basis, through the appRoles property of the application manifest. The value property of each application role is the value that appears in the roles claim.

Example SAML Value:
<Attribute Name="http://schemas.microsoft.com/ws/2008/06/identity/claims/role">
<AttributeValue>Admin</AttributeValue>

Example JWT Value:
“roles”: ["Admin", … ]

https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-token-and-claims

evnexus commented 6 years ago

I don't know if this was implemented before or after my message, but the solution to it is:

  getRoles() {
    const context = Authentication.getContext(this.createConfig());
    let user: any = context.getUser() != null ? context.getUser() : null;
    return user.roles;
  }