Skip to content

Commit ef87385

Browse files
committed
add public getClaims and getGroups function
1 parent 7e95c92 commit ef87385

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

src/Microsoft/Provider.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,28 @@ public static function additionalConfigKeys(): array
233233
];
234234
}
235235

236+
/**
237+
* Get all claims from the ID_TOKEN
238+
*/
239+
public function getClaims()
240+
{
241+
if ($idToken = $this->parseIdToken($this->credentialsResponseBody)) {
242+
243+
return $this->validate($idToken);
244+
}
245+
246+
return [];
247+
}
248+
249+
/**
250+
* Get the optional groups from the ID_TOKEN.
251+
* https://learn.microsoft.com/en-us/entra/identity-platform/optional-claims-reference
252+
*/
253+
public function getGroups()
254+
{
255+
return $this->getClaims()?->groups ?? [];
256+
}
257+
236258
/**
237259
* Get user's roles from the ID_TOKEN.
238260
* https://learn.microsoft.com/en-us/entra/identity-platform/optional-claims#configure-groups-optional-claims
@@ -241,12 +263,7 @@ public static function additionalConfigKeys(): array
241263
*/
242264
public function getRoles(): array
243265
{
244-
if ($idToken = $this->parseIdToken($this->credentialsResponseBody)) {
245-
246-
$claims = $this->validate($idToken);
247-
}
248-
249-
return $claims?->roles ?? [];
266+
return $this->getClaims()?->roles ?? [];
250267
}
251268

252269
/**
@@ -257,14 +274,7 @@ public function getRoles(): array
257274
*/
258275
public function isConsumerTenant(): bool
259276
{
260-
if ($idToken = $this->parseIdToken($this->credentialsResponseBody)) {
261-
262-
$claims = $this->validate($idToken);
263-
264-
return ($claims?->tid ?? '') === self::MS_ENTRA_CONSUMER_TENANT_ID;
265-
}
266-
267-
return false;
277+
return ($this->getClaims()?->tid ?? '') === self::MS_ENTRA_CONSUMER_TENANT_ID;
268278
}
269279

270280
/**

0 commit comments

Comments
 (0)