Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Microsoft resource owner #2012

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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',
]);
}
}