Skip to content

Commit

Permalink
Azure AD B2C Custom Domains (#1013)
Browse files Browse the repository at this point in the history
Co-authored-by: atymic <[email protected]>
  • Loading branch information
kurucu and atymic authored Jul 17, 2023
1 parent d63542b commit 5659b9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ private function getOpenIdConfiguration()

try {
$discovery = sprintf(
'https://%s.b2clogin.com/%s.onmicrosoft.com/%s/v2.0/.well-known/openid-configuration',
$this->getConfig('domain'),
$this->getConfig('domain'),
'https://%s/%s/%s/v2.0/.well-known/openid-configuration',
$this->getConfig('custom_domain', $this->getConfig('domain').'.b2clogin.com'),
$this->getConfig('tenant', $this->getConfig('domain').'.onmicrosoft.com'),
$this->getB2CPolicy()
);

Expand Down Expand Up @@ -198,7 +198,10 @@ private function validateIdToken($idToken)
protected function mapUserToObject(array $user)
{
return (new User())->setRaw($user)->map([
'id' => $user['sub'],
'id' => $user['sub'],
'nickname' => $user['name'],
'name' => $user['name'],
'email' => $user['emails'][0],
]);
}

Expand All @@ -224,6 +227,8 @@ public static function additionalConfigKeys()
'policy',
'redirect_template',
'default_algorithm',
'custom_domain',
'tenant',
];
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ Please see the [Base Installation Guide](https://socialiteproviders.com/usage/),
'domain' => env('AADB2C_Domain'), // {your_domain}.b2clogin.com
'policy' => env('AADB2C_Policy'), // such as 'b2c_1_user_susi'
'default_algorithm' => env('AADB2C_DefaultAlgorithm'), // optional, decoding algorithm JWK key such as 'RS256'
'custom_domain' => env('AADB2C_CUSTOM_DOMAIN'), // optional - set to use your custom domain e.g. login.contoso.com
'tenant' => env('AADB2C_TENANT'), // optional - set to use your tenant ID or custom domain in place of the default onmicrosoft.com one
],
```

To set up your Azure AD B2C custom domain, follow [these instructions](https://learn.microsoft.com/en-us/azure/active-directory-b2c/custom-domain?pivots=b2c-user-flow).

### Add provider event listener

Configure the package's listener to listen for `SocialiteWasCalled` events.
Expand Down

0 comments on commit 5659b9b

Please sign in to comment.