auth0 / auth0-PHP

PHP SDK for Auth0 Authentication and Management APIs.
https://auth0.com/docs/libraries/auth0-php
MIT License
380 stars 209 forks source link

[SDK-4393] feat(auth): Support Organization Name with Authorization API #719

Closed evansims closed 1 year ago

evansims commented 1 year ago

Changes

Note Your Auth0 tenant must have this feature enabled to use this.

This PR adds support for authorizing using an organization name. This enhances the existing support for authorizing using an organization ID. Example usage follows:

✨ (New) Authorization using an organization name:

new Auth0(
  new SdkConfiguration(
    organization: ['example-org-name'],
  )
);

(Existing) support for authorization using an organization ID:

new Auth0(
  new SdkConfiguration(
    organization: ['org_123456'],
  )
);

(Updated) The SDK treats the organization parameter as an allowlist for applications that need to work with multiple organizations. It now accepts organization names, as well as existing support for IDs.

$sdk = new Auth0(
  new SdkConfiguration(
    organization: ['org_123456', 'example-org-name', 'another-org-name'],
  )
);

(Existing) When redirecting for authorization, the organization allowlist's first value is used by default. This behavior can be overridden using method parameters:

// Redirects to /authorize?organization=org_123456&...
header('Location: ' . $sdk->login());
// Redirects to /authorize?organization=org_000000&...
header('Location: ' . $sdk->login(params: ['organization': 'org_000000'));
// Redirects to /authorize?organization=example-org-name&...
header('Location: ' . $sdk->login(params: ['organization': 'example-org-name'));
// Redirects to /authorize?...
header('Location: ' . $sdk->login(params: ['organization': null));

References

Please review the internal Jira ticket SDK-4393 for further information.

Testing

Contributor Checklist

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (efa11eb) 100.00% compared to head (1d9240b) 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #719 +/- ## =========================================== Coverage 100.00% 100.00% - Complexity 1311 1327 +16 =========================================== Files 62 62 Lines 4587 4613 +26 =========================================== + Hits 4587 4613 +26 ``` | Flag | Coverage Δ | | |---|---|---| | unittests | `100.00% <100.00%> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0#carryforward-flags-in-the-pull-request-comment) to find out more. | [Impacted Files](https://app.codecov.io/gh/auth0/auth0-PHP/pull/719?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0) | Coverage Δ | | |---|---|---| | [src/Configuration/SdkConfiguration.php](https://app.codecov.io/gh/auth0/auth0-PHP/pull/719?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0#diff-c3JjL0NvbmZpZ3VyYXRpb24vU2RrQ29uZmlndXJhdGlvbi5waHA=) | `100.00% <ø> (ø)` | | | [src/Token.php](https://app.codecov.io/gh/auth0/auth0-PHP/pull/719?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0#diff-c3JjL1Rva2VuLnBocA==) | `100.00% <100.00%> (ø)` | | | [src/Token/Validator.php](https://app.codecov.io/gh/auth0/auth0-PHP/pull/719?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0#diff-c3JjL1Rva2VuL1ZhbGlkYXRvci5waHA=) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

evansims commented 1 year ago

Thanks @stevehobbsdev, updated with changes to reflect that conversation.