@@ -21,35 +21,39 @@ export class StartOIDCLoginViewModel extends ViewModel {
21
21
constructor ( options ) {
22
22
super ( options ) ;
23
23
this . _isBusy = true ;
24
- this . _authorizationEndpoint = null ;
24
+ this . _issuer = options . loginOptions . oidc . issuer ;
25
+ this . _homeserver = options . loginOptions . homeserver ;
25
26
this . _api = new OidcApi ( {
26
27
clientId : "hydrogen-web" ,
27
- issuer : options . loginOptions . oidc . issuer ,
28
+ issuer : this . _issuer ,
28
29
request : this . platform . request ,
29
30
encoding : this . platform . encoding ,
30
31
} ) ;
31
- this . _homeserver = options . loginOptions . homeserver ;
32
32
}
33
33
34
34
get isBusy ( ) { return this . _isBusy ; }
35
- get authorizationEndpoint ( ) { return this . _authorizationEndpoint ; }
36
35
37
- async start ( ) {
36
+ setBusy ( status ) {
37
+ this . _isBusy = status ;
38
+ this . emitChange ( "isBusy" ) ;
39
+ }
40
+
41
+ async discover ( ) {
42
+ // Ask for the metadata once so it gets discovered and cached
43
+ await this . _api . metadata ( )
44
+ }
45
+
46
+ async startOIDCLogin ( ) {
38
47
const p = this . _api . generateParams ( "openid" ) ;
39
48
await Promise . all ( [
40
49
this . platform . settingsStorage . setInt ( `oidc_${ p . state } _started_at` , Date . now ( ) ) ,
41
50
this . platform . settingsStorage . setString ( `oidc_${ p . state } _nonce` , p . nonce ) ,
42
51
this . platform . settingsStorage . setString ( `oidc_${ p . state } _code_verifier` , p . codeVerifier ) ,
43
52
this . platform . settingsStorage . setString ( `oidc_${ p . state } _homeserver` , this . _homeserver ) ,
44
- this . platform . settingsStorage . setString ( `oidc_${ p . state } _issuer` , this . _api . issuer ) ,
53
+ this . platform . settingsStorage . setString ( `oidc_${ p . state } _issuer` , this . _issuer ) ,
45
54
] ) ;
46
55
47
- this . _authorizationEndpoint = await this . _api . authorizationEndpoint ( p ) ;
48
- this . _isBusy = false ;
49
- }
50
-
51
- setBusy ( status ) {
52
- this . _isBusy = status ;
53
- this . emitChange ( "isBusy" ) ;
56
+ const link = await this . _api . authorizationEndpoint ( p ) ;
57
+ this . platform . openUrl ( link ) ;
54
58
}
55
59
}
0 commit comments