I often work in a hybrid GIS environment, using both QGIS and ArcGIS/ESRI suite of software. Most of the time, I use ArcGIS Pro which connects seamlessly to my ArcGIS Online (AGOL) content. However, there are times when I need to connect to my AGOL content from a QGIS desktop environment. It's easy to connect to a public ArcGIS REST server, but what if you want to connect to a private one? There are a few different ways you can securely connect to an ArcGIS REST server/AGOL. Here I will show you two options: 1) token authentication , 2) OAuth2 Authentication. The post is written in 2 parts. This is part 1.
AGOL Token Authenication
Generating a token Using Postman
There are several ways you can generate a AGOL token. I easiest and most convenient way I find is to use Postman, a popular API testing tool. You can sign up for a free account.
Go to Postman site, and login or and sign up for a free account
Create a new HTTP request by clicking the + button
Set the following options:
Change the HTTP method from GET to POST
Set the URL to: https://www.arcgis.com/sharing/generateToken?f=json&referer=https://www.arcgis.com
Select the Body and x-www-form-urlencoded
Enter 3 Key/Value pairs:
username: your AGOL account username
password: your AGOL password
expiration: 20160
NOTE: expiration is time in minutes. This is important to specify otherwise the default token expiration time is 60 minutes. Token is valid for ~14 days only - the maximum allowed by AGOL. See ArcGIS REST sharing documentation for more information on generating tokens.
Click Send button
4. Note the token and expiration are returned in the Response section. You will use this token in QGIS to securely connect to your AGOL resources. Note that the expiration is given in milliseconds since January 1, 1970 (UTC). If you convert this to a human readable date — it is about 14 days from when the token was generated.
Saving the AGOL Token in QGIS
In QGIS (I am using QGIS 3.34), go to Settings >> Options >> Authentication
In the Authentication Configurations >> Click the Add button
Optional: If you have not setup a master authentication password for QGIS before, then it will prompt you to create one. Do this if needed
In the new Authentication Configuration window:
Give a name to your authentication method
Select ESRI Token from the drop down list
Token: Copy and Paste the token (without quotes) that was generated from Postman
Click Save
Click OK to close Settings window
Connecting Securely to ArcGIS Server using the token
Add a new ArcGIS REST server connection via the Browser panel (right click ArcGIS REST Servers>> new Connection) or via the Data Source Manager ( Layer >> Data Source Manager >> ArcGIS Rest Server >> New)
In the new ArcGIS REST Server Connection window:
Name your Connection
URL: enter the ArcGIS base server resource you want to connect to (eg: arcgis/rest/services or arcgis/rest/services/DemoMap/FeatureServer)
Select the token authentication configuration you created earlier
Click OK
3. If you are using the Data Source Manager then don’t forget to click the Connect button. If you’re using the Browser panel, then you should also see it listed
After connecting to the ArcGIS server you should be able to see your resource. In my example, here I connected to my base server so I can see my private (DemoMap_WF1) and public (FootprintUHSample, test) Feature Servers.
Tips for adding data to your map
Depending on your data, when connecting to the Feature Server you may want to check the option to only request features overlapping the current view extent.
Zoom into your AOI first before adding the data may help speed things up if there are a lot of data that’s being called.
Here is an example map using the data from the AGOL Feature Server I just connected to using a token.
This is it for this post. In Part 2 I will go over AGOL OAuth2 Authentication for use QGIS (which I hope to post soon).
Thanks for reading. Until next time.