2525use OCP \AppFramework \Http \RedirectResponse ;
2626use OCP \AppFramework \Http \Response ;
2727use OCP \AppFramework \Http \StandaloneTemplateResponse ;
28+ use OCP \AppFramework \Services \IInitialState ;
2829use OCP \AppFramework \Utility \ITimeFactory ;
2930use OCP \Authentication \Exceptions \InvalidTokenException ;
3031use OCP \Authentication \Token \IToken ;
3536use OCP \IRequest ;
3637use OCP \ISession ;
3738use OCP \IURLGenerator ;
38- use OCP \IUser ;
3939use OCP \IUserSession ;
4040use OCP \Security \ICrypto ;
4141use OCP \Security \ISecureRandom ;
4242use OCP \Session \Exceptions \SessionNotAvailableException ;
43+ use OCP \Util ;
4344
4445#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE )]
4546class ClientFlowLoginController extends Controller {
@@ -61,6 +62,7 @@ public function __construct(
6162 private IEventDispatcher $ eventDispatcher ,
6263 private ITimeFactory $ timeFactory ,
6364 private IConfig $ config ,
65+ private IInitialState $ initialState ,
6466 ) {
6567 parent ::__construct ($ appName , $ request );
6668 }
@@ -135,24 +137,36 @@ public function showAuthPickerPage(string $clientIdentifier = '', string $user =
135137 $ csp ->addAllowedFormActionDomain ('nc://* ' );
136138 }
137139
140+ $ this ->initialState ->provideInitialState ('loginFlowState ' , 'auth ' );
141+ $ this ->initialState ->provideInitialState ('loginFlowAuth ' , [
142+ 'client ' => $ clientName ,
143+ 'clientIdentifier ' => $ clientIdentifier ,
144+ 'instanceName ' => $ this ->defaults ->getName (),
145+ 'stateToken ' => $ stateToken ,
146+ 'serverHost ' => $ this ->getServerPath (),
147+ 'oauthState ' => $ this ->session ->get ('oauth.state ' ),
148+ 'direct ' => (bool )$ direct ,
149+ 'providedRedirectUri ' => $ providedRedirectUri ,
150+ 'loginRedirectUrl ' => $ this ->urlGenerator ->linkToRoute (
151+ 'core.ClientFlowLogin.grantPage ' ,
152+ [
153+ 'stateToken ' => $ stateToken ,
154+ 'clientIdentifier ' => $ clientIdentifier ,
155+ 'oauthState ' => $ this ->session ->get ('oauth.state ' ),
156+ 'user ' => $ user ,
157+ 'direct ' => $ direct ,
158+ 'providedRedirectUri ' => $ providedRedirectUri ,
159+ ]),
160+ 'appTokenUrl ' => $ this ->urlGenerator ->linkToRouteAbsolute ('core.ClientFlowLogin.apptokenRedirect ' ),
161+ ]);
162+
163+
164+ Util::addScript ('core ' , 'login_flow ' );
138165 $ response = new StandaloneTemplateResponse (
139166 $ this ->appName ,
140- 'loginflow/authpicker ' ,
141- [
142- 'client ' => $ clientName ,
143- 'clientIdentifier ' => $ clientIdentifier ,
144- 'instanceName ' => $ this ->defaults ->getName (),
145- 'urlGenerator ' => $ this ->urlGenerator ,
146- 'stateToken ' => $ stateToken ,
147- 'serverHost ' => $ this ->getServerPath (),
148- 'oauthState ' => $ this ->session ->get ('oauth.state ' ),
149- 'user ' => $ user ,
150- 'direct ' => $ direct ,
151- 'providedRedirectUri ' => $ providedRedirectUri ,
152- ],
153- 'guest '
167+ 'loginflow ' ,
168+ renderAs: 'guest '
154169 );
155-
156170 $ response ->setContentSecurityPolicy ($ csp );
157171 return $ response ;
158172 }
@@ -188,26 +202,31 @@ public function grantPage(
188202 $ csp ->addAllowedFormActionDomain ('nc://* ' );
189203 }
190204
191- /** @var IUser $user */
192205 $ user = $ this ->userSession ->getUser ();
193-
206+ \assert ($ user !== null );
207+
208+ $ this ->initialState ->provideInitialState ('loginFlowState ' , 'grant ' );
209+ $ this ->initialState ->provideInitialState ('loginFlowGrant ' , [
210+ 'actionUrl ' => $ this ->urlGenerator ->linkToRouteAbsolute (
211+ 'core.ClientFlowLogin.generateAppPassword ' ,
212+ ),
213+ 'client ' => $ clientName ,
214+ 'clientIdentifier ' => $ clientIdentifier ,
215+ 'instanceName ' => $ this ->defaults ->getName (),
216+ 'stateToken ' => $ stateToken ,
217+ 'serverHost ' => $ this ->getServerPath (),
218+ 'oauthState ' => $ this ->session ->get ('oauth.state ' ),
219+ 'direct ' => $ direct ,
220+ 'providedRedirectUri ' => $ providedRedirectUri ,
221+ 'userDisplayName ' => $ user ->getDisplayName (),
222+ 'userId ' => $ user ->getUID (),
223+ ]);
224+
225+ Util::addScript ('core ' , 'login_flow ' );
194226 $ response = new StandaloneTemplateResponse (
195227 $ this ->appName ,
196- 'loginflow/grant ' ,
197- [
198- 'userId ' => $ user ->getUID (),
199- 'userDisplayName ' => $ user ->getDisplayName (),
200- 'client ' => $ clientName ,
201- 'clientIdentifier ' => $ clientIdentifier ,
202- 'instanceName ' => $ this ->defaults ->getName (),
203- 'urlGenerator ' => $ this ->urlGenerator ,
204- 'stateToken ' => $ stateToken ,
205- 'serverHost ' => $ this ->getServerPath (),
206- 'oauthState ' => $ this ->session ->get ('oauth.state ' ),
207- 'direct ' => $ direct ,
208- 'providedRedirectUri ' => $ providedRedirectUri ,
209- ],
210- 'guest '
228+ 'loginflow ' ,
229+ renderAs: 'guest '
211230 );
212231
213232 $ response ->setContentSecurityPolicy ($ csp );
0 commit comments