Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions src/Microsoft/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,28 @@ public static function additionalConfigKeys(): array
];
}

/**
* Get all claims from the ID_TOKEN
*/
public function getClaims()
{
if ($idToken = $this->parseIdToken($this->credentialsResponseBody)) {

return $this->validate($idToken);
}

return [];
}

/**
* Get the optional groups from the ID_TOKEN.
* https://learn.microsoft.com/en-us/entra/identity-platform/optional-claims-reference
*/
public function getGroups()
{
return $this->getClaims()?->groups ?? [];
}

/**
* Get user's roles from the ID_TOKEN.
* https://learn.microsoft.com/en-us/entra/identity-platform/optional-claims#configure-groups-optional-claims
Expand All @@ -241,12 +263,7 @@ public static function additionalConfigKeys(): array
*/
public function getRoles(): array
{
if ($idToken = $this->parseIdToken($this->credentialsResponseBody)) {

$claims = $this->validate($idToken);
}

return $claims?->roles ?? [];
return $this->getClaims()?->roles ?? [];
}

/**
Expand All @@ -257,14 +274,7 @@ public function getRoles(): array
*/
public function isConsumerTenant(): bool
{
if ($idToken = $this->parseIdToken($this->credentialsResponseBody)) {

$claims = $this->validate($idToken);

return ($claims?->tid ?? '') === self::MS_ENTRA_CONSUMER_TENANT_ID;
}

return false;
return ($this->getClaims()?->tid ?? '') === self::MS_ENTRA_CONSUMER_TENANT_ID;
}

/**
Expand Down
Loading