@@ -28,11 +28,7 @@ import { _getCurrentUrl } from '../core/util/location';
28
28
import { _open , AuthPopup } from '../core/util/popup' ;
29
29
import { ApiKey , AppName , Auth } from '../model/auth' ;
30
30
import {
31
- AuthEventType ,
32
- EventManager ,
33
- GapiAuthEvent ,
34
- GapiOutcome ,
35
- PopupRedirectResolver
31
+ AuthEventType , EventManager , GapiAuthEvent , GapiOutcome , PopupRedirectResolver
36
32
} from '../model/popup_redirect' ;
37
33
import { _openIframe } from './iframe/iframe' ;
38
34
@@ -41,7 +37,7 @@ import { _openIframe } from './iframe/iframe';
41
37
*/
42
38
const WIDGET_URL = '__/auth/handler' ;
43
39
44
- export class BrowserPopupRedirectResolver implements PopupRedirectResolver {
40
+ class BrowserPopupRedirectResolver implements PopupRedirectResolver {
45
41
private eventManager : EventManager | null = null ;
46
42
private initializationPromise : Promise < EventManager > | null = null ;
47
43
@@ -61,6 +57,16 @@ export class BrowserPopupRedirectResolver implements PopupRedirectResolver {
61
57
return _open ( auth . name , url , _generateEventId ( ) ) ;
62
58
}
63
59
60
+ async _openRedirect (
61
+ auth : Auth ,
62
+ provider : externs . AuthProvider ,
63
+ authType : AuthEventType ,
64
+ eventId ?: string
65
+ ) : Promise < never > {
66
+ window . location . href = getRedirectUrl ( auth , provider , authType , eventId ) ;
67
+ return new Promise ( ( ) => { } ) ;
68
+ }
69
+
64
70
_initialize ( auth : Auth ) : Promise < EventManager > {
65
71
if ( this . eventManager ) {
66
72
return Promise . resolve ( this . eventManager ) ;
@@ -78,11 +84,12 @@ export class BrowserPopupRedirectResolver implements PopupRedirectResolver {
78
84
const eventManager = new AuthEventManager ( auth . name ) ;
79
85
iframe . register < GapiAuthEvent > (
80
86
'authEvent' ,
81
- async ( message : GapiAuthEvent ) => {
82
- await eventManager . onEvent ( message . authEvent ) ;
87
+ ( { authEvent } : GapiAuthEvent ) => {
88
+ const handled = eventManager . onEvent ( authEvent ) ;
83
89
90
+ console . log ( handled ? 'Handled auth message' : 'Other-window message' ) ;
84
91
// We always ACK with the iframe
85
- return { status : GapiOutcome . ACK } ;
92
+ return { status : handled ? GapiOutcome . ACK : GapiOutcome . ERROR } ;
86
93
} ,
87
94
gapi . iframes . CROSS_ORIGIN_IFRAMES_FILTER
88
95
) ;
@@ -92,6 +99,8 @@ export class BrowserPopupRedirectResolver implements PopupRedirectResolver {
92
99
}
93
100
}
94
101
102
+ export const browserPopupRedirectResolver : externs . PopupRedirectResolver = BrowserPopupRedirectResolver ;
103
+
95
104
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
96
105
type WidgetParams = {
97
106
apiKey : ApiKey ;
@@ -130,7 +139,7 @@ function getRedirectUrl(
130
139
if ( ! isEmpty ( provider . getCustomParameters ( ) ) ) {
131
140
params . customParameters = JSON . stringify ( provider . getCustomParameters ( ) ) ;
132
141
}
133
- const scopes = provider . getScopes ( ) ;
142
+ const scopes = provider . getScopes ( ) . filter ( scope => scope !== '' ) ;
134
143
if ( scopes . length > 0 ) {
135
144
params . scopes = scopes . join ( ',' ) ;
136
145
}
@@ -147,6 +156,12 @@ function getRedirectUrl(
147
156
params . tid = auth . tenantId ;
148
157
}
149
158
159
+ for ( const key of Object . keys ( params ) ) {
160
+ if ( ( params as Record < string , unknown > ) [ key ] === undefined ) {
161
+ delete ( params as Record < string , unknown > ) [ key ] ;
162
+ }
163
+ }
164
+
150
165
// TODO: maybe set eid as endipointId
151
166
// TODO: maybe set fw as Frameworks.join(",")
152
167
@@ -156,5 +171,7 @@ function getRedirectUrl(
156
171
) . slice ( 1 ) } `
157
172
) ;
158
173
174
+ console . log ( url ) ;
175
+
159
176
return url . toString ( ) ;
160
177
}
0 commit comments