Quick Report Template secure webmap

683
6
Jump to solution
01-03-2020 06:29 AM
LaurynasGedminas2
Occasional Contributor

Hello, Added this code to the RefineLocationPage.qml to be able to use secure webmap's, it works with username and password part, but it does not work with token part. why?

Connections {
                target: AuthenticationManager // singleton instance
                onAuthenticationChallenge: {
                    console.log("LG-authentication challenge for", challenge.requestUrl)
                    var user = rot13(app.settings.value("username",""))
                    var password = rot13(app.settings.value("password",""));
                    var token = app.settings.value("token","");
                    if (challenge.authenticationChallengeType === Enums.AuthenticationChallengeTypeUsernamePassword) {

                        /*var credential = ArcGISRuntimeEnvironment.createObject("Credential", {
                                                                                   username: user,
                                                                                   password: password
                                                                               });*/


                        console.log(token);
                        var credential = ArcGISRuntimeEnvironment.createObject("Credential", {
                                                                               "token": token
                                                                               });
                        //credential.token = app.token
                        challenge.continueWithCredential(credential);

                    }
                }
            }

Thank you,

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ErwinSoekianto
Esri Regular Contributor

Technically this is how you generate the OAuth token for ArcGIS Online or Enterprise, Generate Token—ArcGIS REST API: Users, groups, and content | ArcGIS for Developers 

----

But here is the thing, in Quick Report template, we are handling the feature layer data collection workflow by calling the REST endpoint of the feature layer directly, hence appending token works. 

Only for WebMap section in the RefineLocationPage.qml, it is loaded using the ArcGIS Runtime SDK for Qt workflow, where it needs to use Portal Object and Authentication Manager to access the OAuth2 authentication when using secure items. See this doc, Access the ArcGIS platform—ArcGIS Runtime SDK for Qt | ArcGIS for Developers 

This can be seen in Map Viewer template where we are fully using ArcGIS Runtime OAuth2 authentication and Portal object to handle the logins. 

View solution in original post

0 Kudos
6 Replies
ErwinSoekianto
Esri Regular Contributor

Laurynas, 

My first guess would be that the token might not be valid. How did you generate the token? 

What error message are you seeing in the console log when using the token instead of username/password? 

Erwin

0 Kudos
LaurynasGedminas2
Occasional Contributor

The token is generated thru featureServiceManager.generateToken() with users credentials.

Where is no errors when the page loads, just says "Map is not available offline","Click to refresh"

Also noticed that Authentication Challenges different url if i use username:

sharing/rest/content/items/4900f753936e47ddb96d5cc19d0b0be6

vs token:

sharing/rest/content/items/4900f753936e47ddb96d5cc19d0b0be6/data

Is this has something to do with my problem?

0 Kudos
ErwinSoekianto
Esri Regular Contributor

I think that is the token for the feature layer that is used in the Quick Report app, not necessarily the same as the webmap that is loaded from ArcGIS Online. 

Are you expecting to skip the login when using a secure webmap in Quick Report app? 

0 Kudos
LaurynasGedminas2
Occasional Contributor

I have customized the QuickReport to ask for log in after the LandingPage finishes loading (Component.onCompleted).

code checks if token is expired and asks to relogin, then token is used thru out the App.

Just manually tested token generated thru 'sharing/rest/generateToken', and it still does not work.

Thank you,

0 Kudos
ErwinSoekianto
Esri Regular Contributor

Technically this is how you generate the OAuth token for ArcGIS Online or Enterprise, Generate Token—ArcGIS REST API: Users, groups, and content | ArcGIS for Developers 

----

But here is the thing, in Quick Report template, we are handling the feature layer data collection workflow by calling the REST endpoint of the feature layer directly, hence appending token works. 

Only for WebMap section in the RefineLocationPage.qml, it is loaded using the ArcGIS Runtime SDK for Qt workflow, where it needs to use Portal Object and Authentication Manager to access the OAuth2 authentication when using secure items. See this doc, Access the ArcGIS platform—ArcGIS Runtime SDK for Qt | ArcGIS for Developers 

This can be seen in Map Viewer template where we are fully using ArcGIS Runtime OAuth2 authentication and Portal object to handle the logins. 

0 Kudos
LaurynasGedminas2
Occasional Contributor

ok makes sense.

0 Kudos