Skip to content

Commit f1e6f17

Browse files
authored
Merge pull request #1962 from malteschlueter/feature/add-resource-owner-passage
2 parents 73bdb88 + 86706a9 commit f1e6f17

File tree

5 files changed

+192
-0
lines changed

5 files changed

+192
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ This bundle contains support for 58 different providers:
6161
* Mail.ru
6262
* Odnoklassniki,
6363
* Office365,
64+
* Passage,
6465
* PayPal,
6566
* QQ,
6667
* RunKeeper,

docs/2-configuring_resource_owners.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ hwi_oauth:
6262
- [Linkedin](resource_owners/linkedin.md)
6363
- [Mail.ru](resource_owners/mailru.md)
6464
- [Odnoklassniki](resource_owners/odnoklassniki.md)
65+
- [Passage](resource_owners/passage.md)
6566
- [PayPal](resource_owners/paypal.md)
6667
- [QQ](resource_owners/qq.md)
6768
- [Reddit](resource_owners/reddit.md)

docs/resource_owners/passage.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Step 2x: Setup Passage
2+
=====================
3+
First you will have to register your application on Passage. Check out the
4+
documentation for more information: https://docs.passage.id/hosted-login/creating-a-new-app.
5+
6+
Next configure a resource owner of type `passage` with appropriate
7+
`client_id`, `client_secret` & `options.sub_domain`. For the available scopes (default: `openid email`) you should
8+
check official Passage documentation: https://docs.passage.id/hosted-login/oidc-client-configuration
9+
10+
```yaml
11+
# config/packages/hwi_oauth.yaml
12+
13+
hwi_oauth:
14+
resource_owners:
15+
any_name:
16+
type: passage
17+
client_id: <client_id>
18+
client_secret: <client_secret>
19+
options:
20+
sub_domain: <sub_domain>
21+
```
22+
23+
When you're done. Continue by configuring the security layer or go back to
24+
setup more resource owners.
25+
26+
- [Step 2: Configuring resource owners (Facebook, GitHub, Google, Windows Live and others](../2-configuring_resource_owners.md)
27+
- [Step 3: Configuring the security layer](../3-configuring_the_security_layer.md).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the HWIOAuthBundle package.
5+
*
6+
* (c) Hardware Info <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace HWI\Bundle\OAuthBundle\OAuth\ResourceOwner;
13+
14+
use Symfony\Component\OptionsResolver\Options;
15+
use Symfony\Component\OptionsResolver\OptionsResolver;
16+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
17+
18+
final class PassageResourceOwner extends GenericOAuth2ResourceOwner
19+
{
20+
public const TYPE = 'passage';
21+
22+
/**
23+
* {@inheritdoc}
24+
*/
25+
protected array $paths = [
26+
'identifier' => 'sub',
27+
'email' => 'email',
28+
'phone_number' => 'phone_number',
29+
'email_verified' => 'email_verified',
30+
'phone_number_verified' => 'phone_number_verified',
31+
];
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function revokeToken($token)
37+
{
38+
if (!isset($this->options['revoke_token_url'])) {
39+
throw new AuthenticationException('OAuth error: "Method unsupported."');
40+
}
41+
42+
$parameters = [
43+
'client_id' => $this->options['client_id'],
44+
'client_secret' => $this->options['client_secret'],
45+
'token' => $token,
46+
];
47+
48+
$response = $this->httpRequest($this->normalizeUrl($this->options['revoke_token_url']), $parameters, [], 'POST');
49+
50+
return 200 === $response->getStatusCode();
51+
}
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
protected function configureOptions(OptionsResolver $resolver)
57+
{
58+
parent::configureOptions($resolver);
59+
60+
$resolver->setDefaults([
61+
'authorization_url' => 'https://{sub_domain}.withpassage.com/authorize',
62+
'access_token_url' => 'https://{sub_domain}.withpassage.com/token',
63+
'revoke_token_url' => 'https://{sub_domain}.withpassage.com/revoke',
64+
'infos_url' => 'https://{sub_domain}.withpassage.com/userinfo',
65+
66+
'use_commas_in_scope' => false,
67+
'scope' => 'openid email',
68+
]);
69+
70+
$resolver->setRequired([
71+
'sub_domain',
72+
]);
73+
74+
$normalizer = function (Options $options, $value) {
75+
return str_replace('{sub_domain}', $options['sub_domain'], $value);
76+
};
77+
78+
$resolver
79+
->setNormalizer('authorization_url', $normalizer)
80+
->setNormalizer('access_token_url', $normalizer)
81+
->setNormalizer('revoke_token_url', $normalizer)
82+
->setNormalizer('infos_url', $normalizer)
83+
;
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the HWIOAuthBundle package.
5+
*
6+
* (c) Hardware Info <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace HWI\Bundle\OAuthBundle\Tests\OAuth\ResourceOwner;
13+
14+
use HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\PassageResourceOwner;
15+
use HWI\Bundle\OAuthBundle\OAuth\Response\AbstractUserResponse;
16+
use HWI\Bundle\OAuthBundle\Test\OAuth\ResourceOwner\GenericOAuth2ResourceOwnerTestCase;
17+
18+
final class PassageResourceOwnerTest extends GenericOAuth2ResourceOwnerTestCase
19+
{
20+
protected string $resourceOwnerClass = PassageResourceOwner::class;
21+
22+
protected array $options = [
23+
'client_id' => 'clientid',
24+
'client_secret' => 'clientsecret',
25+
'sub_domain' => 'subdomain',
26+
];
27+
28+
protected string $userResponse = <<<json
29+
{
30+
"sub": "cIouEYQZIxZkz69XlAGvQDeN",
31+
"email": "[email protected]",
32+
"email_verified": true,
33+
"phone_number_verified": false
34+
}
35+
json;
36+
37+
protected array $paths = [
38+
'identifier' => 'sub',
39+
'email' => 'email',
40+
'phone_number' => 'phone_number',
41+
'email_verified' => 'email_verified',
42+
'phone_number_verified' => 'phone_number_verified',
43+
];
44+
45+
protected string $authorizationUrlBasePart = 'https://subdomain.withpassage.com/authorize?response_type=code&client_id=clientid&scope=openid+email';
46+
47+
public function testGetUserInformation(): void
48+
{
49+
$resourceOwner = $this->createResourceOwner(
50+
[],
51+
[],
52+
[
53+
$this->createMockResponse($this->userResponse),
54+
]
55+
);
56+
57+
/** @var AbstractUserResponse $userResponse */
58+
$userResponse = $resourceOwner->getUserInformation($this->tokenData);
59+
60+
$this->assertSame('cIouEYQZIxZkz69XlAGvQDeN', $userResponse->getUsername());
61+
$this->assertEquals('token', $userResponse->getAccessToken());
62+
$this->assertNull($userResponse->getRefreshToken());
63+
$this->assertNull($userResponse->getExpiresIn());
64+
}
65+
66+
public function testRevokeToken(): void
67+
{
68+
$resourceOwner = $this->createResourceOwner(
69+
[],
70+
[],
71+
[
72+
$this->createMockResponse($this->userResponse, 'application/json'),
73+
]
74+
);
75+
76+
$this->assertTrue($resourceOwner->revokeToken('token'));
77+
}
78+
}

0 commit comments

Comments
 (0)