I am familiar with using secured content in AGOL with the ArcGIS Runtime. But we also have an ArcGIS Portal installed in our company. And there we are able to log in with an enterprise account, which in fact is an active directory account.
So, when I use an AGOL account, I initialize credentials in this way:
<SPAN class="comment token">// use the authentication manager to generate a credential for the portal</SPAN>
<SPAN class="keyword token">var</SPAN> cred <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> AuthenticationManager<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GenerateCredentialAsync</SPAN><SPAN class="punctuation token">(</SPAN>
<SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Uri</SPAN><SPAN class="punctuation token">(</SPAN>agolUrl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"MyAgolUserName"</SPAN><SPAN class="punctuation token">,</SPAN>
password<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// add the credential if it was generated successfully</SPAN>
AuthenticationManager<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN><SPAN class="token function">AddCredential</SPAN><SPAN class="punctuation token">(</SPAN>cred<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>
But how to do when using an enterprise account?
<SPAN class="comment token">// use the authentication manager to generate a credential for the portal</SPAN>
<SPAN class="keyword token">var</SPAN> cred <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> AuthenticationManager<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GenerateCredentialAsync</SPAN><SPAN class="punctuation token">(</SPAN>
<SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Uri</SPAN><SPAN class="punctuation token">(</SPAN>agolUrl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-email-small" href="mailto:abc@domain.com" rel="nofollow noopener noreferrer" target="_blank">abc@domain.com</A><SPAN>"</SPAN></SPAN><SPAN class="punctuation token">,</SPAN>
password<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">// add the credential if it was generated successfully</SPAN>
AuthenticationManager<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN><SPAN class="token function">AddCredential</SPAN><SPAN class="punctuation token">(</SPAN>cred<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>
The same, if I use "domain.com\abc" instead.
This way I got an error:
You do not have permissions to access this resource or perform this operation.