Skip to content

Commit cdcd5e9

Browse files
authored
Merge pull request #116 from topcoder-platform/forums-issue-689
Universal nav integration updates
2 parents 95e71f4 + c3791a6 commit cdcd5e9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Topcoder/class.topcoder.plugin.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ public function settingsController_topcoder_create($sender) {
219219
'Plugins.Topcoder.SSO.CookieName' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Cookie Name'],
220220
'Plugins.Topcoder.SSO.TopcoderHS256.UsernameClaim' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Username Claim for HS256 JWT'],
221221
'Plugins.Topcoder.SSO.TopcoderRS256.UsernameClaim' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Username Claim for RS256 JWT'],
222+
'Plugins.Topcoder.SSO.TopcoderHS256.UserIDClaim' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder User ID Claim for HS256 JWT'],
223+
'Plugins.Topcoder.SSO.TopcoderRS256.UserIDClaim' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder User ID Claim for RS256 JWT'],
224+
'Plugins.Topcoder.SSO.TopcoderHS256.PhotoUrlClaim' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Photo URL Claim for HS256 JWT'],
225+
'Plugins.Topcoder.SSO.TopcoderRS256.PhotoUrlClaim' => ['Control' => 'TextBox', 'Default' => '', 'Description' => 'Topcoder Photo URL Claim for RS256 JWT'],
222226
]);
223227

224228
$cf->renderAll();
@@ -373,16 +377,22 @@ public function gdn_auth_startAuthenticator_handler() {
373377

374378
$AUTH0_AUDIENCE = null;
375379
$USERNAME_CLAIM = null;
380+
$PHOTOURL_CLAIM = null;
381+
$USERID_CLAIM = null;
376382
if ($decodedToken->getHeader('alg') === 'RS256') {
377383
$AUTH0_AUDIENCE = c('Plugins.Topcoder.SSO.TopcoderRS256.ID');
378384
$USERNAME_CLAIM = c('Plugins.Topcoder.SSO.TopcoderRS256.UsernameClaim');
385+
$USERID_CLAIM = c('Plugins.Topcoder.SSO.TopcoderRS256.UserIDClaim');
386+
$PHOTOURL_CLAIM = c('Plugins.Topcoder.SSO.TopcoderRS256.PhotoUrlClaim');
379387
$jwksUri = $issuer . '.well-known/jwks.json';
380388
$jwksHttpOptions = ['base_uri' => $jwksUri];
381389
$jwksFetcher = new JWKFetcher($this->cacheHandler, $jwksHttpOptions);
382390
$signatureVerifier = new AsymmetricVerifier($jwksFetcher);
383391

384392
} else if ($decodedToken->getHeader('alg') === 'HS256') {
385393
$USERNAME_CLAIM = c('Plugins.Topcoder.SSO.TopcoderHS256.UsernameClaim');
394+
$USERID_CLAIM = c('Plugins.Topcoder.SSO.TopcoderHS256.UserIDClaim');
395+
$PHOTOURL_CLAIM = c('Plugins.Topcoder.SSO.TopcoderHS256.PhotoUrlClaim');
386396
$AUTH0_AUDIENCE = c('Plugins.Topcoder.SSO.TopcoderHS256.ID');
387397
$CLIENT_H256SECRET = c('Plugins.Topcoder.SSO.TopcoderHS256.Secret');
388398
$signatureVerifier = new SymmetricVerifier($CLIENT_H256SECRET);
@@ -450,8 +460,11 @@ public function gdn_auth_startAuthenticator_handler() {
450460
$this->checkTopcoderRoles($topcoderRoles);
451461

452462
$topcoderUserName = $decodedToken->getClaim($USERNAME_CLAIM);
463+
$topcoderPhotoUrl = $decodedToken->getClaim($PHOTOURL_CLAIM);
464+
$topcoderUserID = $decodedToken->getClaim($USERID_CLAIM);
465+
453466
if ($topcoderUserName) {
454-
self::log('Trying to signIn ...', ['username' => $topcoderUserName]);
467+
self::log('Trying to signIn ...', ['username' => $topcoderUserName, 'topcoderId'=> $topcoderUserID , 'photoUrl' => $topcoderPhotoUrl, ]);
455468

456469
$userModel = new UserModel();
457470
$user = $userModel->getByUsername($topcoderUserName, false);
@@ -515,6 +528,10 @@ public function gdn_auth_startAuthenticator_handler() {
515528
self::log('The session could not be started.', []);
516529
throw new ClientException('The session could not be started.', 401);
517530
}
531+
532+
Gdn::userModel()->saveAttribute(
533+
Gdn::session()->UserID,
534+
['TopcoderUserID' => $topcoderUserID, 'TopcoderPhotoUrl' => $topcoderPhotoUrl]);
518535
} else {
519536
self::log('Go with the next Vanilla Authenticator', []);
520537
}

0 commit comments

Comments
 (0)