44
55namespace SimpleSAML \Module \oidc \Controllers \Admin ;
66
7+ use SimpleSAML \Locale \Translate ;
78use SimpleSAML \Module \oidc \Admin \Authorization ;
9+ use SimpleSAML \Module \oidc \Bridges \SspBridge ;
10+ use SimpleSAML \Module \oidc \Codebooks \ParametersEnum ;
811use SimpleSAML \Module \oidc \Codebooks \RoutesEnum ;
912use SimpleSAML \Module \oidc \Entities \Interfaces \ClientEntityInterface ;
1013use SimpleSAML \Module \oidc \Exceptions \OidcException ;
1114use SimpleSAML \Module \oidc \Factories \TemplateFactory ;
1215use SimpleSAML \Module \oidc \Repositories \AllowedOriginRepository ;
1316use SimpleSAML \Module \oidc \Repositories \ClientRepository ;
1417use SimpleSAML \Module \oidc \Services \AuthContextService ;
18+ use SimpleSAML \Module \oidc \Services \SessionMessagesService ;
19+ use SimpleSAML \Module \oidc \Utils \Routes ;
1520use Symfony \Component \HttpFoundation \Request ;
1621use Symfony \Component \HttpFoundation \Response ;
1722
@@ -22,6 +27,9 @@ public function __construct(
2227 protected readonly Authorization $ authorization ,
2328 protected readonly ClientRepository $ clientRepository ,
2429 protected readonly AllowedOriginRepository $ allowedOriginRepository ,
30+ protected readonly SspBridge $ sspBridge ,
31+ protected readonly SessionMessagesService $ sessionMessagesService ,
32+ protected readonly Routes $ routes ,
2533 ) {
2634 $ this ->authorization ->requireAdminOrUserWithPermission (AuthContextService::PERM_CLIENT );
2735 }
@@ -33,7 +41,7 @@ public function __construct(
3341 */
3442 protected function getClientFromRequest (Request $ request ): ClientEntityInterface
3543 {
36- ($ clientId = $ request ->query ->getString (' client_id ' ))
44+ ($ clientId = $ request ->query ->getString (ParametersEnum::ClientId-> value ))
3745 || throw new OidcException ('Client ID not provided. ' );
3846
3947 $ authedUserId = $ this ->authorization ->isAdmin () ? null : $ this ->authorization ->getUserId ();
@@ -50,7 +58,6 @@ public function index(Request $request): Response
5058
5159 $ pagination = $ this ->clientRepository ->findPaginated ($ page , $ query , $ authedUserId );
5260
53-
5461 return $ this ->templateFactory ->build (
5562 'oidc:clients.twig ' ,
5663 [
@@ -71,14 +78,39 @@ public function show(Request $request): Response
7178 $ client = $ this ->getClientFromRequest ($ request );
7279 $ allowedOrigins = $ this ->allowedOriginRepository ->get ($ client ->getIdentifier ());
7380
74- // TODO mivanci rename *-ssp.twig templates after removing old ones.
7581 return $ this ->templateFactory ->build (
76- 'oidc:clients/show-ssp .twig ' ,
82+ 'oidc:clients/show.twig ' ,
7783 [
7884 'client ' => $ client ,
7985 'allowedOrigins ' => $ allowedOrigins ,
8086 ],
8187 RoutesEnum::AdminClients->value ,
8288 );
8389 }
90+
91+ /**
92+ * @throws \SimpleSAML\Module\oidc\Exceptions\OidcException
93+ */
94+ public function resetSecret (Request $ request ): Response
95+ {
96+ $ client = $ this ->getClientFromRequest ($ request );
97+
98+ $ oldSecret = $ request ->request ->get ('secret ' );
99+
100+ if ($ oldSecret !== $ client ->getSecret ()) {
101+ throw new OidcException ('Client secret does not match. ' );
102+ }
103+
104+ $ client ->restoreSecret ($ this ->sspBridge ->utils ()->random ()->generateID ());
105+ $ authedUserId = $ this ->authorization ->isAdmin () ? null : $ this ->authorization ->getUserId ();
106+ $ this ->clientRepository ->update ($ client , $ authedUserId );
107+
108+ $ message = Translate::noop ('Client secret has been reset. ' );
109+ $ this ->sessionMessagesService ->addMessage ($ message );
110+
111+ return $ this ->routes ->getRedirectResponseToModuleUrl (
112+ RoutesEnum::AdminClientsShow->value ,
113+ [ParametersEnum::ClientId->value => $ client ->getIdentifier ()],
114+ );
115+ }
84116}
0 commit comments