88 */
99namespace OCA \OAuth2 \Controller ;
1010
11+ use OC \Core \Controller \ClientFlowLoginController ;
1112use OCA \OAuth2 \Db \ClientMapper ;
1213use OCA \OAuth2 \Exceptions \ClientNotFoundException ;
1314use OCP \AppFramework \Controller ;
1718use OCP \AppFramework \Http \Attribute \UseSession ;
1819use OCP \AppFramework \Http \RedirectResponse ;
1920use OCP \AppFramework \Http \TemplateResponse ;
21+ use OCP \IAppConfig ;
2022use OCP \IL10N ;
2123use OCP \IRequest ;
2224use OCP \ISession ;
2325use OCP \IURLGenerator ;
26+ use OCP \Security \ISecureRandom ;
2427
2528class LoginRedirectorController extends Controller {
2629 /**
@@ -38,6 +41,8 @@ public function __construct(
3841 private ClientMapper $ clientMapper ,
3942 private ISession $ session ,
4043 private IL10N $ l ,
44+ private ISecureRandom $ random ,
45+ private IAppConfig $ appConfig ,
4146 ) {
4247 parent ::__construct ($ appName , $ request );
4348 }
@@ -76,12 +81,28 @@ public function authorize($client_id,
7681
7782 $ this ->session ->set ('oauth.state ' , $ state );
7883
79- $ targetUrl = $ this ->urlGenerator ->linkToRouteAbsolute (
80- 'core.ClientFlowLogin.showAuthPickerPage ' ,
81- [
82- 'clientIdentifier ' => $ client ->getClientIdentifier (),
83- ]
84- );
84+ if (in_array ($ client ->getName (), $ this ->appConfig ->getValueArray ('oauth2 ' , 'autoGrantApplications ' , []))) {
85+ /* See ClientFlowLoginController::showAuthPickerPage */
86+ $ stateToken = $ this ->random ->generate (
87+ 64 ,
88+ ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS
89+ );
90+ $ this ->session ->set (ClientFlowLoginController::STATE_NAME , $ stateToken );
91+ $ targetUrl = $ this ->urlGenerator ->linkToRouteAbsolute (
92+ 'core.ClientFlowLogin.grantPage ' ,
93+ [
94+ 'stateToken ' => $ stateToken ,
95+ 'clientIdentifier ' => $ client ->getClientIdentifier (),
96+ ]
97+ );
98+ } else {
99+ $ targetUrl = $ this ->urlGenerator ->linkToRouteAbsolute (
100+ 'core.ClientFlowLogin.showAuthPickerPage ' ,
101+ [
102+ 'clientIdentifier ' => $ client ->getClientIdentifier (),
103+ ]
104+ );
105+ }
85106 return new RedirectResponse ($ targetUrl );
86107 }
87108}
0 commit comments