2626use OCP \Authentication \Exceptions \InvalidTokenException ;
2727use OCP \Defaults ;
2828use OCP \EventDispatcher \IEventDispatcher ;
29+ use OCP \IAppConfig ;
2930use OCP \IL10N ;
3031use OCP \IRequest ;
3132use OCP \ISession ;
@@ -55,6 +56,7 @@ public function __construct(
5556 private ICrypto $ crypto ,
5657 private IEventDispatcher $ eventDispatcher ,
5758 private ITimeFactory $ timeFactory ,
59+ private IAppConfig $ appConfig ,
5860 ) {
5961 parent ::__construct ($ appName , $ request );
6062 }
@@ -157,9 +159,11 @@ public function showAuthPickerPage(string $clientIdentifier = '', string $user =
157159 #[NoCSRFRequired]
158160 #[UseSession]
159161 #[FrontpageRoute(verb: 'GET ' , url: '/login/flow/grant ' )]
160- public function grantPage (string $ stateToken = '' ,
162+ public function grantPage (
163+ string $ stateToken = '' ,
161164 string $ clientIdentifier = '' ,
162- int $ direct = 0 ): StandaloneTemplateResponse {
165+ int $ direct = 0 ,
166+ ): Response {
163167 if (!$ this ->isValidToken ($ stateToken )) {
164168 return $ this ->stateTokenForbiddenResponse ();
165169 }
@@ -181,6 +185,10 @@ public function grantPage(string $stateToken = '',
181185 /** @var IUser $user */
182186 $ user = $ this ->userSession ->getUser ();
183187
188+ if (in_array ($ clientName , $ this ->appConfig ->getValueArray ('oauth2 ' , 'autoGrantApplications ' , []))) {
189+ return $ this ->generateAppPassword ($ stateToken , $ clientIdentifier );
190+ }
191+
184192 $ response = new StandaloneTemplateResponse (
185193 $ this ->appName ,
186194 'loginflow/grant ' ,
@@ -203,14 +211,13 @@ public function grantPage(string $stateToken = '',
203211 return $ response ;
204212 }
205213
206- /**
207- * @return Http\RedirectResponse|Response
208- */
209214 #[NoAdminRequired]
210215 #[UseSession]
211216 #[FrontpageRoute(verb: 'POST ' , url: '/login/flow ' )]
212- public function generateAppPassword (string $ stateToken ,
213- string $ clientIdentifier = '' ) {
217+ public function generateAppPassword (
218+ string $ stateToken ,
219+ string $ clientIdentifier = '' ,
220+ ): Response {
214221 if (!$ this ->isValidToken ($ stateToken )) {
215222 $ this ->session ->remove (self ::STATE_NAME );
216223 return $ this ->stateTokenForbiddenResponse ();
0 commit comments