User constantly challenged for credentials when trying to load WebMap from portal into UWP application

212
0
10-08-2020 01:40 AM
DmitroLukash
New Contributor II

Hello! Maybe someone could help me.

I’m trying to develop a UWP app and show a WebMap from my enterprise portal. My map is made of Feature Service which consist of 2 layers and 5 tables related to each other.

So, I’ve taken a pars of code examples for authentication:

// Register the server information with the AuthenticationManager.
            ServerInfo serverInfo = new ServerInfo(new Uri(PortalUrl))
            {
                //ServerUri = new Uri(PortalUrl),
                TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit,
                OAuthClientInfo = new OAuthClientInfo(clientId: AppClientId, redirectUri: new Uri(OAuthRedirectUrl))
            };
 
            // If a client secret has been configured, set the authentication type to OAuthAuthorizationCode.
 
            if (!String.IsNullOrEmpty(ClientSecret))
            {
                // Use OAuthAuthorizationCode if you need a refresh token (and have specified a valid client secret).
                serverInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode;
                serverInfo.OAuthClientInfo.ClientSecret = ClientSecret;
            }
 
            
 
            // Register this server with AuthenticationManager.
            AuthenticationManager.Current.RegisterServer(serverInfo);
 
 
            // Use a function in this class to challenge for credentials.
            AuthenticationManager.Current.ChallengeHandler = new DefaultChallengeHandler { AllowSaveCredentials = true };

 

My “ClientSecret” is set so (!String.IsNullOrEmpty(ClientSecret)) is true.

 

But when I add a map to a MapView control. I have to authenticate myself more than once.

As I found out I am challenged the first time to get to the Portal and the second is to get to the ArcGis Server.

After successful authentications I have 2 credentials:

 

AuthenticationManager.Current.Credentials.ToList()

Count = 2

    [0]: {Esri.ArcGISRuntime.Security.ArcGISTokenCredential}

    [1]: {Esri.ArcGISRuntime.Security.OAuthTokenCredential}

 

I don’t know why, but the second authentication not always leads to success. So, please, make it clear for me:

1.How can I challenge User for credential only once and give him an access to all resources on Portal and Server.

2.How to store credentials and reuse it after application’s restart.

 

Thanks!

0 Kudos
0 Replies