Skip to content

Commit

Permalink
Add PBS Account registration flow route
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher C. Wells committed Feb 17, 2022
1 parent da5d9ae commit 1971386
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions social_auth_pbs.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ social_auth_pbs.redirect_to_pbs:
options:
no_cache: TRUE

social_auth_pbs.redirect_to_pbs_register:
path: 'user/login/pbs-register'
defaults:
_controller: '\Drupal\social_auth_pbs\Controller\PbsRegisterController::redirectToProvider'
requirements:
# Anonymous users can log in, but authenticated users can also associate a new provider.
_access: 'TRUE'
options:
no_cache: TRUE

social_auth_pbs.redirect_to_apple:
path: 'user/login/pbs-apple'
defaults:
Expand Down
29 changes: 29 additions & 0 deletions src/Controller/PbsRegisterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Drupal\social_auth_pbs\Controller;

use Drupal\Core\Routing\TrustedRedirectResponse;

/**
* Returns responses for special Social Auth PBS Account register routes.
*
* This controller generates a URL that sends the user first through an account
* creation flow and then through the regular OAuth2 authorization flow.
*/
class PbsRegisterController extends PbsAuthController {

/**
* {@inheritdoc}
*/
public function redirectToProvider() {
$response = parent::redirectToProvider();
if ($response instanceof TrustedRedirectResponse) {
$url_parts = parse_url($response->getTargetUrl());
$next = urlencode("{$url_parts['path']}?{$url_parts['query']}");
$register_url = "{$url_parts['scheme']}://{$url_parts['host']}/oauth2/register/?next=$next";
$response->setTrustedTargetUrl($register_url);
}
return $response;
}

}

0 comments on commit 1971386

Please sign in to comment.