@@ -24,6 +24,16 @@ import {
24
24
import { NODEJS_DEFAULT_REFERER_HEADER } from "./index.js" ;
25
25
import { AuthenticationManagerBase } from "./AuthenticationManagerBase.js" ;
26
26
27
+ /**
28
+ * distinguish between an ICredential and IArcGISIdentityManagerOptions
29
+ */
30
+ function isCredential ( credential : any ) : credential is ICredential {
31
+ return (
32
+ typeof credential . userId === "string" ||
33
+ typeof credential . expires === "number"
34
+ ) ;
35
+ }
36
+
27
37
/**
28
38
* Options for {@linkcode ArcGISIdentityManager.fromToken}.
29
39
*/
@@ -905,12 +915,16 @@ export class ArcGISIdentityManager
905
915
private static parentMessageHandler ( event : any ) : ArcGISIdentityManager {
906
916
if ( event . data . type === "arcgis:auth:credential" ) {
907
917
const credential = event . data . credential as ICredential ;
908
- const serverInfo = {
909
- hasPortal : true ,
910
- hasServer : false ,
911
- server : credential . server
912
- } as IServerInfo ;
913
- return ArcGISIdentityManager . fromCredential ( credential , serverInfo ) ;
918
+ // at 4.x - 4.5 we were passing .toJSON() instead of .toCredential()
919
+ // so we attempt to handle either payload for backwards compatibility
920
+ // but at the next breaking change we should only support an ICredential
921
+ return isCredential ( credential )
922
+ ? ArcGISIdentityManager . fromCredential ( credential , {
923
+ hasPortal : true ,
924
+ hasServer : false ,
925
+ server : credential . server
926
+ } as IServerInfo )
927
+ : new ArcGISIdentityManager ( credential ) ;
914
928
}
915
929
if ( event . data . type === "arcgis:auth:error" ) {
916
930
const err = new Error ( event . data . error . message ) ;
0 commit comments