Hardcoding Username and Password into AuthenticationView

596
2
06-26-2018 05:12 AM
KyleSchultz
New Contributor

I have this 

    AuthenticationView {
        anchors.fill: parent
        authenticationManager: AuthenticationManager
    }

I would like to declare a username and password for a map service without the need of asking the user for a password.

I tried declaring credentials: 

'{"username": "user","password": "pass"}'

but that failed as well...I can't find any documentation on how exactly authenticationManager operates.

 authenticationManager: AuthenticationManager

Any help would be appreciated.

0 Kudos
2 Replies
KyleSchultz
New Contributor

So since no one has answered this question I found a backwards work around for it.

The directory

C:\Users\<username>\Applications\ArcGIS\AppStudio\bin\qml\Esri\ArcGISRuntime\Toolkit

contains files, AuthenticationView.qml and  AuthenticationView20.qml

in both of these files I changed the lines(they are very the same)

 if (Number(challenge.authenticationChallengeType) === 1) {
    // ArcGIS token, HTTP Basic/Digest, IWA
               createView("UserCredentialsView.qml");
            } else if (Number(challenge.authenticationChallengeType) === 2) {
                // OAuth 2
                createView("OAuth2View.qml");
            } else if (Number(challenge.authenticationChallengeType) === 3) {
                // Client Certificate
                createView("ClientCertificateView.qml");
            } else if (Number(challenge.authenticationChallengeType) === 4) {
                // SSL Handshake - Self-signed certificate
                createView("SslHandshakeView.qml");
            }

I changed the first if statement to(making sure to remove createView() or comment it out.)

 if (Number(challenge.authenticationChallengeType) === 1) {
     if (challenge)
                    challenge.continueWithUsernamePassword('username', 'password');
                // ArcGIS token, HTTP Basic/Digest, IWA
                //createView("UserCredentialsView.qml");
            }

}

Now to make sure you project gets built in with it  copy the directory

C:\Users\<username>\Applications\ArcGIS\AppStudio\bin\qml\Esri\ArcGISRuntime\Toolkit

to the project root of your folder and then call

import "ArcGISRuntime/Toolkit/Dialogs" 

within your qml file

and the finally invoke as you would

    AuthenticationView {
        anchors.fill: parent
        authenticationManager: AuthenticationManager // set the authenticationManager property
    }

which will call everything with a hard coded username and password.

This is kind of a backwards way of doing it. If anyone has a cleaner solution I'd much appreciate it.

The documentation for qml and for AuthenticationManager is poor.

0 Kudos
GeneVaatveit
New Contributor

Did you ever find a better way of doing this?  

It seems AuthenticationView.qml has been updated in Toolkit and is no longer compatible with your solution.  However I did find the right version in the Token Authentication sample.

0 Kudos