AnsweredAssumed Answered

OAuth2 authentication challenge

Question asked by cstamatopoulos on Jun 3, 2015
Latest reply on Jun 4, 2015 by dbroux-esristaff

Hi all,

 

I am attempting to switch my standard app licensing from Token to OAuth2.

Things is it is not challenging the user for credential and instead throws an Exception.

Esri.ArcGISRuntime.Http.ArcGISWebException: Error code '400' : 'Unable to generate token.'

'username' must be specified.

'password' must be specified.

 

I should say that It works fine with the token.

 

Here is what I do.

First set up our challenge handler

 

            // setup our sign challenge handler

            var signInChallengeHandler = new Esri.ArcGISRuntime.Toolkit.Security.SignInChallengeHandler()

            {

                AllowSaveCredentials = true,

                CredentialSaveOption = Esri.ArcGISRuntime.Toolkit.Controls.CredentialSaveOption.Unselected

            };

 

            Esri.ArcGISRuntime.Security.IdentityManager.Current.ChallengeHandler = signInChallengeHandler;

            Esri.ArcGISRuntime.Security.IdentityManager.Current.OAuthAuthorizeHandler =

                new Esri.ArcGISRuntime.Toolkit.Security.OAuthAuthorizeHandler();

 

          // code for basic license....

 

Second register the server

 

            var serverInfo = new ServerInfo()

            {

                ServerUri = portalServerUrl,

                OAuthClientInfo = new OAuthClientInfo()

                {

                    ClientId = "xxxxxx",

                    ClientSecret = "xxxxxxxxxx"

                },

                TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode

            };

 

            Esri.ArcGISRuntime.Security.IdentityManager.Current.RegisterServer(serverInfo);

 

Finally request for the credentials

 

                var credRequest = new CredentialRequestInfo()

                {

                    ServiceUri = portalServerUrl,

                };

 

                var cred = await IdentityManager.Current.GetCredentialAsync(credRequest, true);

 

If instead I use

 

                  var cred = await IdentityManager.Current.GenerateCredentialAsync(portalServerUrl, "user", "pass");

 

I get Esri.ArcGISRuntime.Http.ArcGISWebException: Error code '400' : 'client_id not specified'

 

What am I missing here ?

Outcomes