What is the proper way to load secure webmap?
so far this code does not work:
MapView { id: mapView anchors.fill: parent
Credential{ id: creds username: user password: password }
Map {
id: webMap initUrl: webmap_secure
}
So, The code works if i use the username and the password from the Quick Report Template App, it does not work if i use token from the App:
Connections <SPAN class="punctuation token">{</SPAN> target<SPAN class="punctuation token">:</SPAN> AuthenticationManager <SPAN class="comment token">// singleton instance</SPAN> onAuthenticationChallenge<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"LG-authentication challenge for"</SPAN><SPAN class="punctuation token">,</SPAN> challenge<SPAN class="punctuation token">.</SPAN>requestUrl<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">var</SPAN> user <SPAN class="operator token">=</SPAN> <SPAN class="token function">rot13</SPAN><SPAN class="punctuation token">(</SPAN>app<SPAN class="punctuation token">.</SPAN>settings<SPAN class="punctuation token">.</SPAN><SPAN class="token function">value</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"username"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">var</SPAN> password <SPAN class="operator token">=</SPAN> <SPAN class="token function">rot13</SPAN><SPAN class="punctuation token">(</SPAN>app<SPAN class="punctuation token">.</SPAN>settings<SPAN class="punctuation token">.</SPAN><SPAN class="token function">value</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"password"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> token <SPAN class="operator token">=</SPAN> app<SPAN class="punctuation token">.</SPAN>settings<SPAN class="punctuation token">.</SPAN><SPAN class="token function">value</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"token"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>challenge<SPAN class="punctuation token">.</SPAN>authenticationChallengeType <SPAN class="operator token">===</SPAN> Enums<SPAN class="punctuation token">.</SPAN>AuthenticationChallengeTypeUsernamePassword<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">/*var credential = ArcGISRuntimeEnvironment.createObject("Credential", { username: user, password: password });*/</SPAN> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN>token<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> credential <SPAN class="operator token">=</SPAN> ArcGISRuntimeEnvironment<SPAN class="punctuation token">.</SPAN><SPAN class="token function">createObject</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Credential"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="string token">"token"</SPAN><SPAN class="punctuation token">:</SPAN> token <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//credential.token = app.token</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
AppStudio for ArcGIS
Modifying the AppStudio "Quick Report" App, they are storing the token as string. the token works properly if i add single feature layer with:
Credential<SPAN class="punctuation token">{</SPAN> id<SPAN class="punctuation token">:</SPAN> creds token<SPAN class="punctuation token">:</SPAN> app<SPAN class="punctuation token">.</SPAN>settings<SPAN class="punctuation token">.</SPAN><SPAN class="token function">value</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"token"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">}</SPAN> FeatureLayer <SPAN class="punctuation token">{</SPAN> id<SPAN class="punctuation token">:</SPAN> featureLayer <SPAN class="comment token">// feature table</SPAN> ServiceFeatureTable <SPAN class="punctuation token">{</SPAN> id<SPAN class="punctuation token">:</SPAN> featureTable url<SPAN class="punctuation token">:</SPAN> app<SPAN class="punctuation token">.</SPAN>featureLayerURL credential<SPAN class="punctuation token">:</SPAN> creds <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I believe if you want to directly set the token string, you may need to also set the referer property - Credential QML Type | ArcGIS for Developers .
Are you re-generating tokens somewhere else in your app? If you provide username and password instead, the credentials will be stored in the CredentialCache, and expired tokens will be automatically handled in the API. With your workflow, if your token expires, you'll need to handle fetching a new token and providing it to the Runtime API
Thank you for quick response,
could be it be:
<SPAN class="keyword token">var</SPAN> credential <SPAN class="operator token">=</SPAN> ArcGISRuntimeEnvironment<SPAN class="punctuation token">.</SPAN><SPAN class="token function">createObject</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Credential"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="string token">"token"</SPAN><SPAN class="punctuation token">:</SPAN> token <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
its not working right now.
Laurynas
Laurynas-
Because a Map can contain layers and tables that are also secured, you can't directly set a credential on the Map. Instead, you need to use our AuthenticationManager, which is a class that catches all security challenges and notifies the developer, allowing the developer to satisfy the challenge (pass in a credential to the request). This is discussed further here - Access the ArcGIS platform—ArcGIS Runtime SDK for Qt | ArcGIS for Developers
Example code would be:
ApplicationWindow <SPAN class="punctuation token">{</SPAN> id<SPAN class="punctuation token">:</SPAN> appWindow width<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">800</SPAN> height<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">600</SPAN> <SPAN class="comment token">// add a mapView component</SPAN> MapView <SPAN class="punctuation token">{</SPAN> id<SPAN class="punctuation token">:</SPAN> mv anchors<SPAN class="punctuation token">.</SPAN>fill<SPAN class="punctuation token">:</SPAN> parent <SPAN class="comment token">// add a map to the mapview</SPAN> Map <SPAN class="punctuation token">{</SPAN> initUrl<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"securedWebmapUrl"</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> Connections <SPAN class="punctuation token">{</SPAN> target<SPAN class="punctuation token">:</SPAN> AuthenticationManager <SPAN class="comment token">// singleton instance</SPAN> onAuthenticationChallenge<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"authentication challenge for"</SPAN><SPAN class="punctuation token">,</SPAN> challenge<SPAN class="punctuation token">.</SPAN>requestUrl<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>challenge<SPAN class="punctuation token">.</SPAN>authenticationChallengeType <SPAN class="operator token">===</SPAN> Enums<SPAN class="punctuation token">.</SPAN>AuthenticationChallengeTypeUsernamePassword<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> credential <SPAN class="operator token">=</SPAN> ArcGISRuntimeEnvironment<SPAN class="punctuation token">.</SPAN><SPAN class="token function">createObject</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Credential"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN> username<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"username"</SPAN><SPAN class="punctuation token">,</SPAN> password<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"password"</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> challenge<SPAN class="punctuation token">.</SPAN><SPAN class="token function">continueWithCredential</SPAN><SPAN class="punctuation token">(</SPAN>credential<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
If you wanted to instead show a user a dialog to sign in, you could use our Toolkit component called AuthenticationView:
<SPAN class="keyword token">import</SPAN> QtQuick <SPAN class="number token">2.6</SPAN> <SPAN class="keyword token">import</SPAN> QtQuick<SPAN class="punctuation token">.</SPAN>Controls <SPAN class="number token">2.2</SPAN> <SPAN class="keyword token">import</SPAN> QtPositioning <SPAN class="number token">5.12</SPAN> <SPAN class="keyword token">import</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime <SPAN class="number token">100.6</SPAN> <SPAN class="keyword token">import</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Toolkit<SPAN class="punctuation token">.</SPAN>Dialogs <SPAN class="number token">100.6</SPAN> ApplicationWindow <SPAN class="punctuation token">{</SPAN> id<SPAN class="punctuation token">:</SPAN> appWindow width<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">800</SPAN> height<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">600</SPAN> <SPAN class="comment token">// add a mapView component</SPAN> MapView <SPAN class="punctuation token">{</SPAN> id<SPAN class="punctuation token">:</SPAN> mv anchors<SPAN class="punctuation token">.</SPAN>fill<SPAN class="punctuation token">:</SPAN> parent <SPAN class="comment token">// add a map to the mapview</SPAN> Map <SPAN class="punctuation token">{</SPAN> initUrl<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"secureWebmapUrl"</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> AuthenticationView <SPAN class="punctuation token">{</SPAN> authenticationManager<SPAN class="punctuation token">:</SPAN> AuthenticationManager <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.