#ArcGIS Runtime.NET SDK100.0.0 OAuth step by step demo using Named User
##Overview For OAuth 2 authentication explaination, please check this great article.
This demo will show you step by step setup of OAuth authentication using ArcGIS Online Named User.
##Steps
- Register a ArcGIS two month trial. Open the link above. Fill in the forms and following the steps in the web site to complete your ArcGIS trial.
- Login in to your ArcGIS Online Home Page, click My content:
- Click Add item, then Click an application
- Select Application type. Fill in title and tags as you need.
- After Application has been added. Click the item you just added. Click Settings tab.
- Scroll to the bottom. Click Registered Info to check you Oauth app Client Id stuff.
- Fill Registered Info into your code match the infos on the web:
- Build and run OAuth project. Done!
- The Water Mark is gone.
##Licensing code
// Challenge the user for portal credentials (OAuth credential request for arcgis.com)
CredentialRequestInfo loginInfo = new CredentialRequestInfo();
// Use the OAuth implicit grant flow
loginInfo.GenerateTokenOptions = new GenerateTokenOptions
{
TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit
};
// Indicate the url (portal) to authenticate with (ArcGIS Online)
loginInfo.ServiceUri = new Uri("https://www.arcgis.com/sharing/rest");
// Call GetCredentialAsync on the AuthenticationManager to invoke the challenge handler
Credential cred = await AuthenticationManager.Current.GetCredentialAsync(loginInfo, false);
// Connect to the portal (ArcGIS Online) using the credential
ArcGISPortal arcgisPortal = await ArcGISPortal.CreateAsync(loginInfo.ServiceUri, cred);
// Get LicenseInfo from the portal
Esri.ArcGISRuntime.LicenseInfo licenseInfo = arcgisPortal.PortalInfo.LicenseInfo;
var licenseJson = licenseInfo.ToJson();
using (StreamWriter outputFile = new StreamWriter(@"lincese.json"))
{
// you can save the license file for latter offline use.
outputFile.WriteLine(licenseJson);
}
// ... code here to license the app immediately and/or save the license (JSON string) to take the app offline ...
// License the app using the license info
Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.SetLicense(licenseInfo);##System Requirements
-
Visual Studio 2015
-
ArcGIS Runtime.NET SDK100.0.0








