ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.SystemCore Namespace / ISignOnHandler Interface / GenerateCredentials Method
SIGNONHANDLERINFO containing the portal or online Uri
Example

In This Topic
    GenerateCredentials Method
    In This Topic
    GenerateCredentials will be called by the system when authentication is required against a portal or online. This method is for use in CoreHost applications only
    Syntax
    void GenerateCredentials( 
       ref SIGNONHANDLERINFO info
    )
    Sub GenerateCredentials( _
       ByRef info As SIGNONHANDLERINFO _
    ) 

    Parameters

    info
    SIGNONHANDLERINFO containing the portal or online Uri
    Remarks
    Implement your handler to authenticate against the requested portal or online. Note: if the challenge is being initiated by a connection to a federated feature service, the feature service will attempt to authenticate twice (if the first attempt fails).
    Example
    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);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also