@@ -53,11 +53,15 @@ export default class GmfAuthForm extends GmfBaseElement {
53
53
@state ( ) private allowPasswordReset = false ;
54
54
@state ( ) private changingPassword = false ;
55
55
@state ( ) private userMustChangeItsPassword = false ;
56
+ @state ( ) private openIdConnectUrl = '' ;
56
57
@state ( ) private error = false ;
57
58
@state ( ) private otpImage = '' ;
58
59
@state ( ) private gmfUser : User = null ;
59
60
@state ( ) private customCSS_ = '' ;
60
61
private changingPasswordUsername_ = '' ;
62
+ private initialApplicationUrl = window . location . href ;
63
+ private currentApplicationUrl = window . location . href ;
64
+ private openIdConnectBaseUrl = '' ;
61
65
62
66
connectedCallback ( ) : void {
63
67
super . connectedCallback ( ) ;
@@ -73,13 +77,21 @@ export default class GmfAuthForm extends GmfBaseElement {
73
77
}
74
78
} ,
75
79
} ) ,
80
+
76
81
user . getLoginMessage ( ) . subscribe ( {
77
82
next : ( message : string ) => {
78
83
this . loginInfoMessage = message ;
84
+ this . _updateOpenIdConnectUrl ( ) ;
79
85
} ,
80
86
} ) ,
81
87
) ;
82
88
89
+ window . addEventListener ( 'popstate' , ( ) => {
90
+ this . currentApplicationUrl = window . location . href ;
91
+ this . _updateOpenIdConnectUrl ( ) ;
92
+ } ) ;
93
+ this . _updateOpenIdConnectUrl ( ) ;
94
+
83
95
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
84
96
const loginField = document . body . querySelector ( 'input[slot=gmf-auth-login]' ) as HTMLInputElement ;
85
97
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
@@ -97,11 +109,20 @@ export default class GmfAuthForm extends GmfBaseElement {
97
109
} ) ;
98
110
}
99
111
112
+ _updateOpenIdConnectUrl ( ) : void {
113
+ const applicationUrl = this . loginInfoMessage ? this . currentApplicationUrl : this . initialApplicationUrl ;
114
+ const params = new URLSearchParams ( {
115
+ came_from : applicationUrl ,
116
+ } ) ;
117
+ this . openIdConnectUrl = `${ this . openIdConnectBaseUrl } ?${ params . toString ( ) } ` ;
118
+ }
119
+
100
120
// override default initConfig
101
121
initConfig ( configuration : Configuration ) : void {
102
122
this . twoFactorAuth = configuration . gmfTwoFactorAuth ;
103
123
this . allowPasswordChange = configuration . gmfAuthenticationConfig . allowPasswordChange ;
104
124
this . allowPasswordReset = configuration . gmfAuthenticationConfig . allowPasswordReset ;
125
+ this . openIdConnectBaseUrl = configuration . gmfOidcLoginUrl ;
105
126
if ( configuration . gmfCustomCSS && configuration . gmfCustomCSS . authentication !== undefined ) {
106
127
this . customCSS_ = configuration . gmfCustomCSS . authentication ;
107
128
}
@@ -167,7 +188,7 @@ export default class GmfAuthForm extends GmfBaseElement {
167
188
</ div >
168
189
< div class ="form-group ">
169
190
< input
170
- ?hidden ="${ ! this . allowPasswordChange } "
191
+ ?hidden ="${ ! ( this . allowPasswordChange && this . gmfUser . login_type !== 'oidc' ) } "
171
192
type ="button "
172
193
class ="form-control btn btn-default "
173
194
value =${ i18next . t ( 'Change password' ) }
@@ -195,53 +216,57 @@ export default class GmfAuthForm extends GmfBaseElement {
195
216
`
196
217
: '' }
197
218
${ this . gmfUser . username === null && ! this . changingPassword
198
- ? html `
199
- < div >
200
- < form name ="loginForm " role ="form " @submit =${ ( evt : Event ) => this . login ( evt ) } >
201
- < div class ="form-group ">
202
- < slot name ="gmf-auth-login "> </ slot >
203
- </ div >
204
- < div class ="form-group ">
205
- < slot name ="gmf-auth-password "> </ slot >
206
- </ div >
207
- ${ this . twoFactorAuth
208
- ? html `
209
- < div class ="form-group ">
210
- ${ i18next . t ( 'The following field should be kept empty on first login:' ) }
211
- < input
212
- type ="text "
213
- class ="form-control "
214
- name ="otp "
215
- autocomplete ="one-time-code "
216
- placeholder =${ i18next . t ( 'Authentication code' ) }
217
- / >
218
- </ div >
219
- `
220
- : '' }
221
- < div class ="form-group ">
222
- < input type ="submit " class ="form-control btn prime " value =${ i18next . t ( 'Connect' ) } / >
223
- </ div >
224
- ${ this . isLoading
225
- ? html `
226
- < div class ="login-spinner ">
227
- < i class ="fa fa-spin "> ${ svgSpinner ( ) } </ i >
228
- </ div >
229
- `
219
+ ? this . gmfUser . login_type === 'oidc'
220
+ ? html `< a class ="btn prime form-control " role ="button " href ="${ this . openIdConnectUrl } "
221
+ > ${ i18next . t ( 'Connect' ) } </ a
222
+ > `
223
+ : html `
224
+ < div >
225
+ < form name ="loginForm " role ="form " @submit =${ ( evt : Event ) => this . login ( evt ) } >
226
+ < div class ="form-group ">
227
+ < slot name ="gmf-auth-login "> </ slot >
228
+ </ div >
229
+ < div class ="form-group ">
230
+ < slot name ="gmf-auth-password "> </ slot >
231
+ </ div >
232
+ ${ this . twoFactorAuth
233
+ ? html `
234
+ < div class ="form-group ">
235
+ ${ i18next . t ( 'The following field should be kept empty on first login:' ) }
236
+ < input
237
+ type ="text "
238
+ class ="form-control "
239
+ name ="otp "
240
+ autocomplete ="one-time-code "
241
+ placeholder =${ i18next . t ( 'Authentication code' ) }
242
+ / >
243
+ </ div >
244
+ `
245
+ : '' }
246
+ < div class ="form-group ">
247
+ < input type ="submit " class ="form-control btn prime " value =${ i18next . t ( 'Connect' ) } / >
248
+ </ div >
249
+ ${ this . isLoading
250
+ ? html `
251
+ < div class ="login-spinner ">
252
+ < i class ="fa fa-spin "> ${ svgSpinner ( ) } </ i >
253
+ </ div >
254
+ `
255
+ : '' }
256
+ < div ?hidden ="${ ! this . allowPasswordReset } " class ="form-group ">
257
+ < a @click =${ ( evt : Event ) => this . resetPassword ( evt ) } href =""
258
+ > ${ i18next . t ( 'Password forgotten?' ) } </ a
259
+ >
260
+ </ div >
261
+ </ form >
262
+
263
+ ${ this . resetPasswordShown
264
+ ? html ` < div class ="alert alert-info ">
265
+ ${ i18next . t ( 'A new password has just been sent to you by e-mail.' ) }
266
+ </ div > `
230
267
: '' }
231
- < div ?hidden ="${ ! this . allowPasswordReset } " class ="form-group ">
232
- < a @click =${ ( evt : Event ) => this . resetPassword ( evt ) } href =""
233
- > ${ i18next . t ( 'Password forgotten?' ) } </ a
234
- >
235
- </ div >
236
- </ form >
237
-
238
- ${ this . resetPasswordShown
239
- ? html ` < div class ="alert alert-info ">
240
- ${ i18next . t ( 'A new password has just been sent to you by e-mail.' ) }
241
- </ div > `
242
- : '' }
243
- </ div >
244
- `
268
+ </ div >
269
+ `
245
270
: '' }
246
271
${ this . changingPassword
247
272
? html `
0 commit comments