<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Use secured FeatureLayer from ArcGIS Online in ArcGIS Runtime SDK for WPF (Retired) Questions</title>
    <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-wpf-retired-questions/use-secured-featurelayer-from-arcgis-online/m-p/700806#M3570</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- I do not know what to use for the tokenUrl.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You don't have to know the token url, the first url parameter of GenerateCredentialTaskAsync is the ArcGIS secured resource&amp;nbsp; you want to access to. The token wil be discovered automatically internally.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;I would prefer to somehowget this taken care of during application startup. I want the layer to display as soon as the application is loaded.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes. That's possible.&lt;/P&gt;&lt;P&gt;You have actually 2 options:&lt;/P&gt;&lt;P&gt;1) Option 1: Generate a token when an authorization error is intercepted by the IdentityManager (i.e at runtime when trying to access to the secured services)&lt;/P&gt;&lt;P&gt;To do that you have to define a challenge method that will handler the error and can, for example, generate a token with an hardcoded username/password.&lt;/P&gt;&lt;P&gt;As, in this case ,the challenge method is just a call to GenerateCredentialAsync, the IM initialization can be as simple as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current.ChallengeMethod += (url, handler, options) =&amp;gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current.GenerateCredentialAsync(url, &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: 10pt; font-family: Consolas;"&gt;"&amp;lt;username&amp;gt;"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: 10pt; font-family: Consolas;"&gt;"&amp;lt;password&amp;gt;"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;, handler, options);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) Option 2: At startup, generate a token and add it to IM which will use it when trying to access to the service&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Consolas;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Consolas;"&gt;// generate a token&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; crd = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;await&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; Client.&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current&lt;/SPAN&gt;.GenerateCredentialTaskAsync(&amp;lt;resource url&amp;gt;, &amp;lt;username&amp;gt;, &amp;lt;password&amp;gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Consolas;"&gt;// add the token to IM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Client.&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current&lt;/SPAN&gt;.AddCredential(crd);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Consolas;"&gt;// activate IM without challenge (or set a challenge method for managing access to secure services not declared at startup)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;Client.&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current&lt;/SPAN&gt;.Enabled = true&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Dec 2014 18:58:44 GMT</pubDate>
    <dc:creator>DominiqueBroux</dc:creator>
    <dc:date>2014-12-15T18:58:44Z</dc:date>
    <item>
      <title>Use secured FeatureLayer from ArcGIS Online</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-wpf-retired-questions/use-secured-featurelayer-from-arcgis-online/m-p/700805#M3569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Simple question: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I display a secured feature layer on a map in an ArcGIS Runtime for WPF app?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not want to query the user for username/password. I just want to hardcode it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know that I need to use IdentityManager and I have successfully done precisely the above with ArcGIS Server, but for some reason it is not working for me with ArcGIS Online.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I do for ArcGIS Server. I call this function before I use the secured service (it is a GP-service):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;private &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;async&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;Task&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; GenerateToken(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;string&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; tokenUrl, &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;string&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; username, &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;string&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; password)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;&amp;nbsp; IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current.DefaultReferer = &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: 10pt; font-family: Consolas;"&gt;"BlahBlah"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;&amp;nbsp; IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current.ChallengeMethodEx += &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;SignInDialog&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.DoSignInEx; // I don't think that this has any effect.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style=": ; color: #008000; font-size: 10pt; font-family: Consolas;"&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;&amp;nbsp; IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;Credential&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; crd = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;await&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current.GenerateCredentialTaskAsync(tokenUrl, username, password);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;&amp;nbsp; if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; (crd != &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;null&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current.AddCredential(crd);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;&amp;nbsp; else&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;new&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;Exception&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: 10pt; font-family: Consolas;"&gt;"Unknown error"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think that at least two things are different with ArcGIS Online:&lt;/P&gt;&lt;P&gt;- I do not know what to use for the tokenUrl.&lt;/P&gt;&lt;P&gt;- I would prefer to somehowget this taken care of during application startup. I want the layer to display as soon as the application is loaded.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Dec 2014 18:14:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-wpf-retired-questions/use-secured-featurelayer-from-arcgis-online/m-p/700805#M3569</guid>
      <dc:creator>ThomasIsraelsen</dc:creator>
      <dc:date>2014-12-15T18:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: Use secured FeatureLayer from ArcGIS Online</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-wpf-retired-questions/use-secured-featurelayer-from-arcgis-online/m-p/700806#M3570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- I do not know what to use for the tokenUrl.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You don't have to know the token url, the first url parameter of GenerateCredentialTaskAsync is the ArcGIS secured resource&amp;nbsp; you want to access to. The token wil be discovered automatically internally.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;I would prefer to somehowget this taken care of during application startup. I want the layer to display as soon as the application is loaded.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes. That's possible.&lt;/P&gt;&lt;P&gt;You have actually 2 options:&lt;/P&gt;&lt;P&gt;1) Option 1: Generate a token when an authorization error is intercepted by the IdentityManager (i.e at runtime when trying to access to the secured services)&lt;/P&gt;&lt;P&gt;To do that you have to define a challenge method that will handler the error and can, for example, generate a token with an hardcoded username/password.&lt;/P&gt;&lt;P&gt;As, in this case ,the challenge method is just a call to GenerateCredentialAsync, the IM initialization can be as simple as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current.ChallengeMethod += (url, handler, options) =&amp;gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current.GenerateCredentialAsync(url, &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: 10pt; font-family: Consolas;"&gt;"&amp;lt;username&amp;gt;"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #a31515; font-size: 10pt; font-family: Consolas;"&gt;"&amp;lt;password&amp;gt;"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;, handler, options);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) Option 2: At startup, generate a token and add it to IM which will use it when trying to access to the service&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Consolas;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Consolas;"&gt;// generate a token&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; crd = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;await&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt; Client.&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current&lt;/SPAN&gt;.GenerateCredentialTaskAsync(&amp;lt;resource url&amp;gt;, &amp;lt;username&amp;gt;, &amp;lt;password&amp;gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Consolas;"&gt;// add the token to IM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Client.&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current&lt;/SPAN&gt;.AddCredential(crd);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008000; font-size: 10pt; font-family: Consolas;"&gt;// activate IM without challenge (or set a challenge method for managing access to secure services not declared at startup)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Consolas;"&gt;Client.&lt;SPAN style="color: #2b91af; font-size: 10pt; font-family: Consolas;"&gt;IdentityManager&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;.Current&lt;/SPAN&gt;.Enabled = true&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Consolas;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Dec 2014 18:58:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-wpf-retired-questions/use-secured-featurelayer-from-arcgis-online/m-p/700806#M3570</guid>
      <dc:creator>DominiqueBroux</dc:creator>
      <dc:date>2014-12-15T18:58:44Z</dc:date>
    </item>
  </channel>
</rss>

