Skip to content

Commit 74be005

Browse files
committed
Merge #6 Telekom bearer token: additional secret
2 parents e125f9d + a0d3320 commit 74be005

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

lib/Command/UpsertProvider.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function configure() {
7373
->addOption('mapping-quota', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the quota')
7474
->addOption('mapping-uid', null, InputOption::VALUE_OPTIONAL, 'Attribute mapping of the user id')
7575
->addOption('extra-claims', null, InputOption::VALUE_OPTIONAL, 'Extra claims to request when getting tokens')
76-
76+
->addOption('bearersecret', 'bs', InputOption::VALUE_OPTIONAL, 'Telekom bearer token requires a different client secret for bearer tokens')
7777
->addOption(
7878
'output',
7979
null,
@@ -100,11 +100,18 @@ protected function execute(InputInterface $input, OutputInterface $output) {
100100
return $this->listProviders($input, $output);
101101
}
102102

103+
// bearersecret is usually base64 encoded, but SAM delivers it non-encoded
104+
// by default; so always encode/decode for this field
105+
$bearersecret = $input->getOption('bearersecret');
106+
if ($bearersecret !== null) {
107+
$bearersecret = $this->crypto->encrypt(\Base64Url\Base64Url::encode($bearersecret));
108+
}
109+
103110
// check if any option for updating is provided
104111
$updateOptions = array_filter($input->getOptions(), static function ($value, $option) {
105112
return in_array($option, [
106113
'identifier', 'clientid', 'clientsecret', 'discoveryuri',
107-
'scope', 'unique-uid', 'check-bearer',
114+
'scope', 'unique-uid', 'check-bearer', 'bearersecret',
108115
'mapping-uid', 'mapping-display-name', 'mapping-email', 'mapping-quota',
109116
'extra-claims'
110117
]) && $value !== null;
@@ -146,7 +153,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
146153
$scope = $scope ?? 'openid email profile';
147154
}
148155
try {
149-
$provider = $this->providerMapper->createOrUpdateProvider($identifier, $clientid, $clientsecret, $discoveryuri, $scope);
156+
$provider = $this->providerMapper->createOrUpdateProvider($identifier, $clientid, $clientsecret, $discoveryuri, $scope, $bearersecret);
150157
// invalidate JWKS cache (even if it was just created)
151158
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_JWKS_CACHE, '');
152159
$this->providerService->setSetting($provider->getId(), ProviderService::SETTING_JWKS_CACHE_TIMESTAMP, '');

lib/Db/Provider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class Provider extends Entity implements \JsonSerializable {
5555
/** @var string */
5656
protected $scope;
5757

58+
/** @var string */
59+
protected $bearerSecret;
60+
5861
/**
5962
* @return string
6063
*/

lib/Db/ProviderMapper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function getProviders() {
9898
*/
9999
public function createOrUpdateProvider(string $identifier, string $clientid = null,
100100
string $clientsecret = null, string $discoveryuri = null,
101-
string $scope = 'openid email profile') {
101+
string $scope = 'openid email profile', string $bearersecret = null) {
102102
try {
103103
$provider = $this->findProviderByIdentifier($identifier);
104104
} catch (DoesNotExistException $eNotExist) {
@@ -115,6 +115,7 @@ public function createOrUpdateProvider(string $identifier, string $clientid = nu
115115
$provider->setClientSecret($clientsecret);
116116
$provider->setDiscoveryEndpoint($discoveryuri);
117117
$provider->setScope($scope);
118+
$provider->setBearerSecret($bearersecret ?? '');
118119
return $this->insert($provider);
119120
} else {
120121
if ($clientid !== null) {
@@ -126,6 +127,9 @@ public function createOrUpdateProvider(string $identifier, string $clientid = nu
126127
if ($discoveryuri !== null) {
127128
$provider->setDiscoveryEndpoint($discoveryuri);
128129
}
130+
if ($bearerSecret !== null) {
131+
$provider->setBearerSecret($bearersecret);
132+
}
129133
$provider->setScope($scope);
130134
return $this->update($provider);
131135
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OCA\UserOIDC\Migration;
6+
7+
use Closure;
8+
use OCP\DB\ISchemaWrapper;
9+
use OCP\Migration\IOutput;
10+
use OCP\Migration\SimpleMigrationStep;
11+
12+
class Version00008Date20211114183344 extends SimpleMigrationStep {
13+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
14+
/** @var ISchemaWrapper $schema */
15+
$schema = $schemaClosure();
16+
17+
$table = $schema->getTable('user_oidc_providers');
18+
$table->addColumn('bearer_secret', 'string', [
19+
'notnull' => true,
20+
'length' => 64,
21+
]);
22+
23+
return $schema;
24+
}
25+
}

0 commit comments

Comments
 (0)