11import { ArcGISIdentityManager , request } from "@esri/arcgis-rest-request"
22import { ArcGISAuthConfig , AuthType , FeatureServiceConfig , OAuthAuthConfig , TokenAuthConfig , UsernamePasswordAuthConfig } from './ArcGISConfig'
3- import { ObservationProcessor } from "./ObservationProcessor" ;
43
54interface ArcGISIdentityManagerFactory {
6- create ( portal : string , server : string , config : ArcGISAuthConfig , processor ?: ObservationProcessor ) : Promise < ArcGISIdentityManager >
5+ create ( portal : string , server : string , config : ArcGISAuthConfig ) : Promise < ArcGISIdentityManager >
76}
87
98const OAuthIdentityManagerFactory : ArcGISIdentityManagerFactory = {
10- async create ( portal : string , server : string , auth : OAuthAuthConfig , processor : ObservationProcessor ) : Promise < ArcGISIdentityManager > {
9+ async create ( portal : string , server : string , auth : OAuthAuthConfig ) : Promise < ArcGISIdentityManager > {
1110 console . debug ( 'Client ID provided for authentication' )
1211 const { clientId, authToken, authTokenExpires, refreshToken, refreshTokenExpires } = auth
1312
@@ -27,24 +26,27 @@ const OAuthIdentityManagerFactory: ArcGISIdentityManagerFactory = {
2726 httpMethod : 'GET'
2827 } ) ;
2928
29+ // TODO Factory should not handle config changes
3030 // Update authToken to new token
31- const config = await processor . safeGetConfig ( ) ;
32- let service = config . featureServices . find ( service => service . url === portal ) ?. auth as OAuthAuthConfig ;
33- const date = new Date ( ) ;
34- date . setSeconds ( date . getSeconds ( ) + response . expires_in || 0 ) ;
35- service = {
36- ...service ,
37- authToken : response . access_token ,
38- authTokenExpires : date . getTime ( )
39- }
31+ // const config = await processor.safeGetConfig();
32+ // let service = config.featureServices.find(service => service.url === portal)?.auth as OAuthAuthConfig;
33+ // const date = new Date();
34+ // date.setSeconds(date.getSeconds() + response.expires_in || 0);
35+ // service = {
36+ // ...service,
37+ // authToken: response.access_token,
38+ // authTokenExpires: date.getTime()
39+ // }
40+ // await processor.putConfig(config)
4041
41- await processor . putConfig ( config )
42- return ArcGISIdentityManager . fromToken ( {
43- clientId : clientId ,
44- token : response . access_token ,
45- tokenExpires : date ,
46- portal : portal
47- } ) ;
42+ // return ArcGISIdentityManager.fromToken({
43+ // clientId: clientId,
44+ // token: response.access_token,
45+ // tokenExpires: date,
46+ // portal: portal
47+ // });
48+
49+ throw new Error ( 'TODO Unsupported' )
4850 } catch ( error ) {
4951 throw new Error ( 'Error occurred when using refresh token' )
5052 }
@@ -86,8 +88,7 @@ const authConfigMap: { [key: string]: ArcGISIdentityManagerFactory } = {
8688}
8789
8890export function getIdentityManager (
89- config : FeatureServiceConfig ,
90- processor : ObservationProcessor
91+ config : FeatureServiceConfig
9192) : Promise < ArcGISIdentityManager > {
9293 const auth = config . auth
9394 const authType = config . auth ?. type
@@ -98,7 +99,7 @@ export function getIdentityManager(
9899 if ( ! factory ) {
99100 throw new Error ( `No factory found for type ${ authType } ` )
100101 }
101- return factory . create ( getPortalUrl ( config . url ) , getServerUrl ( config . url ) , auth , processor )
102+ return factory . create ( getPortalUrl ( config . url ) , getServerUrl ( config . url ) , auth )
102103}
103104
104105
0 commit comments