Access private map in ARCGIS studio without login to arcgis online

766
4
Jump to solution
07-20-2020 09:57 PM
rsharma
Occasional Contributor III

Hi i want to access my maps(private). in my application , but they always ask for the login credentials.

I want to make it accessible without login.

DO I need to add credential of username and password and token,

How to generate token in arcgis to pass in credentials, to access private map without login 

I used this example to write the below code https://community.esri.com/message/908803-re-simple-app-with-private-webmap?commentID=908803#comment... .

This is my code below:-

import QtQuick 2.6
import QtQuick.Controls 2.1
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtPositioning 5.3
import QtSensors 5.3
import ArcGIS.AppFramework 1.0
import ArcGIS.AppFramework.Controls 1.0
import Esri.ArcGISRuntime 100.6
import Esri.ArcGISRuntime.Toolkit.Dialogs 100.1
import "assets/js/backend.js" as Backend
App{
    id: app
    width: 400
    height: 800
    property real scaleFactor: AppFramework.displayScaleFactor
    property string portalUrl: "https://arcgis.com/sharing/rest/content/items/";
    property string itemID: "mymapid"
    //header bar
    Rectangle {
        id: titleRect
        anchors {
            left: parent.left
            right: parent.right
            top: parent.top
        }
        height: 50 * AppFramework.displayScaleFactor
        color: app.info.propertyValue("titleBackgroundColor", "red")
        Text {
            id: titleText
            anchors.centerIn: parent
            text: app.info.title
            color: app.info.propertyValue("titleTextColor", "white")
            font {
                pointSize: 18
            }
            wrapMode: Text.WrapAtWordBoundaryOrAnywhere
            maximumLineCount: 2
            elide: Text.ElideRight
            horizontalAlignment: Text.AlignHCenter
        }
    }//End Rectangle header
    MapView {
        id:mapView
        property real initialMapRotation: 0
        anchors {
            left: parent.left
            right: parent.right
            top: titleRect.bottom
            bottom: parent.bottom
        }
        rotationByPinchingEnabled: true
        zoomByPinchingEnabled: true
    // add a basemap
    Map {
        id:map
        item: PortalItem {
            portal: portal
            itemId: itemID
        }
        //initUrl: portalUrl + itemID
        }
    }//End Mapview
    //! [PortalUserInfo create portal]
    Portal {
        id: portal
        credential: Credential {
            oAuthClientInfo: OAuthClientInfo {
                oAuthMode: Enums.OAuthModeUser
                clientId: "myclientid" //replace
            }
        }
        Component.onCompleted: {
            load();
            //fetchLicenseInfo();
        }
        onLoadStatusChanged: {
            if (loadStatus === Enums.LoadStatusFailedToLoad)
                retryLoad();
        }
    }
    AuthenticationView {
        id: authView
        authenticationManager: AuthenticationManager
    }
    //! [PortalUserInfo create portal]
    }

					
				
			
			
				
			
			
				
0 Kudos
1 Solution

Accepted Solutions
ErwinSoekianto
Esri Regular Contributor

Rajni, 

I want to point out that you can also use the proxy services to make this work, here is the documentation on how to set it up, Working with Proxy Services | ArcGIS for Developers  

This is the documentation on how to generate a token, Generate Token—ArcGIS REST API | ArcGIS for Developers, in AppStudio you can use the NetworkRequest component from AppFramework or XMLHttpRequest in javascript to make a request to REST endpoint. 

This is the documentation on NetworkRequest component in AppFramework, NetworkRequest QML Type | ArcGIS 

You can follow the sample called Nearby, it has a simple enough Network Manager class that you can copy from, arcgis-appstudio-samples/NetworkManager.qml at fd2e133089b189f3308de210612c3802d474f62b · Esri/arcgi... 

Thank you,

Erwin

View solution in original post

4 Replies
rsharma
Occasional Contributor III

Generate Token—ArcGIS REST API | ArcGIS for Developers 

do this work in my example??

I am very confused. Please help. As accessing these private maps will be done by multipse users of our app, so it need to be used without login.

Any help is appreciable

0 Kudos
ErwinSoekianto
Esri Regular Contributor

Rajni, 

You can try hard-coding the username and password to create the Credentials object based on this ArcGIS Runtime SDK for Qt‌ documentation page, Credential QML Type | ArcGIS for Developers 

Thank you,

Erwin

rsharma
Occasional Contributor III

Hi Erwin,

i have already tried the same, but it still asks for the username and pwd. So i used a temporary access token from ArcGIS for Developers  and it worked. But i don't know how to generate oauth token programatically to pass in credentials for different users. If you could help please give any example of how to generate token to pass in my credentials. 

 //! [PortalUserInfo create portal]
    Portal {
        id: portal
        credential: Credential {
               token: "my temporary developer dashboard access token"
               oAuthClientInfo: OAuthClientInfo {
                oAuthMode: Enums.OAuthModeUser
                clientId: "myclientid" //replace
            }
        }
        Component.onCompleted: {
            load();
            //fetchLicenseInfo();
        }
        onLoadStatusChanged: {
            if (loadStatus === Enums.LoadStatusFailedToLoad)
                retryLoad();
        }
    }
0 Kudos
ErwinSoekianto
Esri Regular Contributor

Rajni, 

I want to point out that you can also use the proxy services to make this work, here is the documentation on how to set it up, Working with Proxy Services | ArcGIS for Developers  

This is the documentation on how to generate a token, Generate Token—ArcGIS REST API | ArcGIS for Developers, in AppStudio you can use the NetworkRequest component from AppFramework or XMLHttpRequest in javascript to make a request to REST endpoint. 

This is the documentation on NetworkRequest component in AppFramework, NetworkRequest QML Type | ArcGIS 

You can follow the sample called Nearby, it has a simple enough Network Manager class that you can copy from, arcgis-appstudio-samples/NetworkManager.qml at fd2e133089b189f3308de210612c3802d474f62b · Esri/arcgi... 

Thank you,

Erwin