Skip to content

Commit

Permalink
Fix azure urls (hwi#1619)
Browse files Browse the repository at this point in the history
* Fix azure urls

* Fix azure tests

* Fix azure doc

* Remove unused import in azure test
  • Loading branch information
mawi12345 authored May 7, 2020
1 parent 1e6fd30 commit 6e7dbf9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 42 deletions.
23 changes: 2 additions & 21 deletions OAuth/ResourceOwner/AzureResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@ public function configure()
$this->options['authorization_url'] = sprintf($this->options['authorization_url'], $this->options['application']);
}

/**
* {@inheritdoc}
*/
public function getAuthorizationUrl($redirectUri, array $extraParameters = [])
{
return parent::getAuthorizationUrl($redirectUri, $extraParameters + ['resource' => $this->options['resource']]);
}

/**
* {@inheritdoc}
*/
public function refreshAccessToken($refreshToken, array $extraParameters = [])
{
return parent::refreshAccessToken($refreshToken, $extraParameters + ['resource' => $this->options['resource']]);
}

/**
* {@inheritdoc}
*
Expand Down Expand Up @@ -96,13 +80,10 @@ protected function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);

$resolver->setRequired(['resource']);

$resolver->setDefaults([
'infos_url' => 'https://graph.microsoft.com/v1.0/me',
'authorization_url' => 'https://login.windows.net/%s/oauth2/authorize',
'access_token_url' => 'https://login.windows.net/%s/oauth2/token',

'authorization_url' => 'https://login.microsoftonline.com/%s/oauth2/v2.0/authorize',
'access_token_url' => 'https://login.microsoftonline.com/%s/oauth2/v2.0/token',
'application' => 'common',
'api_version' => 'v1.0',
'csrf' => true,
Expand Down
7 changes: 3 additions & 4 deletions Resources/doc/resource_owners/azure.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Step 2x: Setup Azure
====================
First you will have to register your application with Azure.
Just follow the steps as described here: http://blogs.msdn.com/b/aadgraphteam/archive/2013/05/17/using-oauth-2-0-authorization-code-grant-for-delegated-access-of-directory-via-aad-graph.aspx
Just follow the steps as described here: https://docs.microsoft.com/en-us/azure/active-directory/saas-apps/openidoauth-tutorial

More details on the Azure and OAuth can be found here https://msdn.microsoft.com/en-us/library/azure/dn645542.aspx and for Azure Active Directory here https://msdn.microsoft.com/en-us/library/azure/hh974476.aspx
More details on the Azure and OAuth can be found here https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols

Next configure a resource owner of type `azure` with appropriate `client_id`,
`client_secret`, and `resource`. You can also specify which `application` it
`client_secret`. You can also specify which `application` it
should target (`common` by default)

```yaml
Expand All @@ -20,7 +20,6 @@ hwi_oauth:
client_secret: <client_secret>

options:
resource: https://graph.windows.net
application: common
```
Expand Down
19 changes: 2 additions & 17 deletions Tests/OAuth/ResourceOwner/AzureResourceOwnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use HWI\Bundle\OAuthBundle\OAuth\Exception\HttpTransportException;
use HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\AzureResourceOwner;
use HWI\Bundle\OAuthBundle\Tests\Fixtures\CustomUserResponse;
use Symfony\Component\Security\Http\HttpUtils;

class AzureResourceOwnerTest extends GenericOAuth2ResourceOwnerTest
{
Expand All @@ -41,13 +40,13 @@ class AzureResourceOwnerTest extends GenericOAuth2ResourceOwnerTest
];

protected $expectedUrls = [
'authorization_url_csrf' => 'http://user.auth/?test=2&response_type=code&client_id=clientid&state=random&redirect_uri=http%3A%2F%2Fredirect.to%2F&resource=https%3A%2F%2Fgraph.windows.net',
'authorization_url_csrf' => 'http://user.auth/?test=2&response_type=code&client_id=clientid&state=random&redirect_uri=http%3A%2F%2Fredirect.to%2F',
];

public function testGetAuthorizationUrl()
{
$this->assertEquals(
$this->options['authorization_url'].'&response_type=code&client_id=clientid&state=random&redirect_uri=http%3A%2F%2Fredirect.to%2F&resource=https%3A%2F%2Fgraph.windows.net',
$this->options['authorization_url'].'&response_type=code&client_id=clientid&state=random&redirect_uri=http%3A%2F%2Fredirect.to%2F',
$this->resourceOwner->getAuthorizationUrl('http://redirect.to/')
);
}
Expand Down Expand Up @@ -110,18 +109,4 @@ public function testGetUserInformationFailure()
$this->assertSame($exception, $e->getPrevious());
}
}

protected function setUpResourceOwner($name, HttpUtils $httpUtils, array $options)
{
return parent::setUpResourceOwner(
$name,
$httpUtils,
array_merge(
[
'resource' => 'https://graph.windows.net',
],
$options
)
);
}
}

0 comments on commit 6e7dbf9

Please sign in to comment.