Skip to content

Commit

Permalink
Add Microsoft resource owner
Browse files Browse the repository at this point in the history
  • Loading branch information
tkierat committed Jul 30, 2024
1 parent c30b61e commit 54e625f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ This bundle contains support for 58 different providers:
* JIRA,
* Keycloak,
* LinkedIn,
* Mail.ru
* Mail.ru,
* Microsoft,
* Odnoklassniki,
* Office365,
* Passage,
Expand Down
1 change: 1 addition & 0 deletions docs/2-configuring_resource_owners.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ hwi_oauth:
- [Keycloak](resource_owners/keycloak.md)
- [Linkedin](resource_owners/linkedin.md)
- [Mail.ru](resource_owners/mailru.md)
- [Microsoft](resource_owners/microsoft.md)
- [Odnoklassniki](resource_owners/odnoklassniki.md)
- [Passage](resource_owners/passage.md)
- [PayPal](resource_owners/paypal.md)
Expand Down
24 changes: 24 additions & 0 deletions docs/resource_owners/microsoft.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Step 2x: Setup Microsoft
===========================
First you will have to register your application on Microsoft. Check out the
documentation for more information: https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app.

Next configure a resource owner of type `microsoft` with appropriate`client_id` and `client_secret`.

```yaml
# config/packages/hwi_oauth.yaml

hwi_oauth:
resource_owners:
any_name:
type: microsoft
client_id: <client_id>
client_secret: <client_secret>

```

When you're done. Continue by configuring the security layer or go back to
setup more resource owners.

- [Step 2: Configuring resource owners (Facebook, GitHub, Google, Windows Live and others](../2-configuring_resource_owners.md)
- [Step 3: Configuring the security layer](../3-configuring_the_security_layer.md).
50 changes: 50 additions & 0 deletions src/OAuth/ResourceOwner/MicrosoftResourceOwner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the HWIOAuthBundle package.
*
* (c) Hardware Info <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace HWI\Bundle\OAuthBundle\OAuth\ResourceOwner;

use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Tomasz Kierat <[email protected]>
*/
final class MicrosoftResourceOwner extends GenericOAuth2ResourceOwner
{
public const TYPE = 'microsoft';

/**
* {@inheritdoc}
*/
protected array $paths = [
'identifier' => 'id',
'nickname' => 'userPrincipalName',
'realname' => 'displayName',
'firstname' => 'givenName',
'lastname' => 'surname',
'email' => 'userPrincipalName'
];

/**
* {@inheritdoc}
*/
protected function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);

$resolver->setDefaults([
'authorization_url' => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
'access_token_url' => 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
'infos_url' => 'https://graph.microsoft.com/v1.0/me',

'scope' => 'https://graph.microsoft.com/user.read',
]);
}
}

0 comments on commit 54e625f

Please sign in to comment.