/License.NetAppByNamedUser

This repository contains sample code demonstrating how to license ArcGIS Runtime.NET SDK100.0.0 App using ArcGIS Online or Portal Named User using Oauth2

Primary LanguageC#MIT LicenseMIT

#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

  1. 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.
  2. Login in to your ArcGIS Online Home Page, click My content:
  3. Click Add item, then Click an application
  4. Select Application type. Fill in title and tags as you need.
  5. After Application has been added. Click the item you just added. Click Settings tab.
  6. Scroll to the bottom. Click Registered Info to check you Oauth app Client Id stuff.
  7. Fill Registered Info into your code match the infos on the web:
  8. Build and run OAuth project. Done!
  9. 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