void GenerateCredentials( ref SIGNONHANDLERINFO info )
Sub GenerateCredentials( _ ByRef info As SIGNONHANDLERINFO _ )
Parameters
- info
- SIGNONHANDLERINFO containing the portal or online Uri
void GenerateCredentials( ref SIGNONHANDLERINFO info )
Sub GenerateCredentials( _ ByRef info As SIGNONHANDLERINFO _ )
internal class ChallengeHandler : ISignOnHandler { private void GetStoredUserNameAndPassword(string url, out string user, out string pwd) { user = ""; pwd = ""; if (url == "https://your_portal/portal/") { //TODO retrieve the relevant credentials } else if (url == "https://your_portal2/portal/") { //etc. } } public void GenerateCredentials(ref SIGNONHANDLERINFO info) { string referer = ""; string token = ""; string user = ""; string superSecretPwd = ""; GetStoredUserNameAndPassword(info.agoURL, out user, out superSecretPwd); //Authenticate var uri = new Uri(info.agoURL, UriKind.Absolute); var ok = ArcGIS.Core.SystemCore.ArcGISSignOn.Instance.SignInWithCredentials( uri, user, superSecretPwd, out referer, out token); if (ok) { //TODO: for example, if you want to retain the token and referer //for your own purposes that code would go here... } } } //Within static void Main(string[] args) or your main program //Set your challenge handler... ArcGIS.Core.SystemCore.ArcGISSignOn.Instance.SetSignonHandler(new ChallengeHandler()); //Establish connection(s) to your desired feature service datasource(s) var my_fs = "https://federated_server/server/rest/services/My_Service/FeatureServer"; //Connect to the FeatureService DB //If Authentication is required, your ChallengeHandler will be invoked //TODO - handle GeodatabaseNotFoundOrOpenedException if authentication fails var uri = new Uri(my_fs, UriKind.Absolute); using (var fsdb = new Geodatabase(new ServiceConnectionProperties(uri))) { //Assuming succesful authentication... } //If you need to clear the handler... ArcGIS.Core.SystemCore.ArcGISSignOn.Instance.SetSignonHandler(null);
Target Platforms: Windows 10, Windows 8.1, Windows 7