Skip to content

Commit 1971386

Browse files
author
Christopher C. Wells
committed
Add PBS Account registration flow route
1 parent da5d9ae commit 1971386

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

social_auth_pbs.routing.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ social_auth_pbs.redirect_to_pbs:
88
options:
99
no_cache: TRUE
1010

11+
social_auth_pbs.redirect_to_pbs_register:
12+
path: 'user/login/pbs-register'
13+
defaults:
14+
_controller: '\Drupal\social_auth_pbs\Controller\PbsRegisterController::redirectToProvider'
15+
requirements:
16+
# Anonymous users can log in, but authenticated users can also associate a new provider.
17+
_access: 'TRUE'
18+
options:
19+
no_cache: TRUE
20+
1121
social_auth_pbs.redirect_to_apple:
1222
path: 'user/login/pbs-apple'
1323
defaults:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Drupal\social_auth_pbs\Controller;
4+
5+
use Drupal\Core\Routing\TrustedRedirectResponse;
6+
7+
/**
8+
* Returns responses for special Social Auth PBS Account register routes.
9+
*
10+
* This controller generates a URL that sends the user first through an account
11+
* creation flow and then through the regular OAuth2 authorization flow.
12+
*/
13+
class PbsRegisterController extends PbsAuthController {
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public function redirectToProvider() {
19+
$response = parent::redirectToProvider();
20+
if ($response instanceof TrustedRedirectResponse) {
21+
$url_parts = parse_url($response->getTargetUrl());
22+
$next = urlencode("{$url_parts['path']}?{$url_parts['query']}");
23+
$register_url = "{$url_parts['scheme']}://{$url_parts['host']}/oauth2/register/?next=$next";
24+
$response->setTrustedTargetUrl($register_url);
25+
}
26+
return $response;
27+
}
28+
29+
}

0 commit comments

Comments
 (0)