lvargasgeotecnologias-esridist

How to Generate Portal Tokens using IWA?

Discussion created by lvargasgeotecnologias-esridist Employee on Sep 2, 2019

Hello,

 

We have an application written in C# which performs user authentication to generate a Portal (10.6) token, this token its used to insert points in a Feature Service, get organization nfo etc.

 

In the past, the "normal/traditional" authentication model using Portal users works fine, the issue is that the environment changes, and now use domain users (Active Directory) and Single Sign-On (SSO) / Integrated Windows Authentication (IWA) for all the Portals users, this change in the IIS has affected this process and now we have the error 401, which is caused for use with authentication method.

 

Has anyone implemented this in the past and knows how to do it? I have tried several alternatives (Negotiate and NTLM) and they have not been functional.

 

This is the code used:

 

    private string _getResponse(NameValueCollection data, string url)
    {
        string responseData;
        var webClient = new WebClient();
        var response = webClient.UploadValues(url, data); -> Here we have the 401 error.
        responseData = System.Text.Encoding.UTF8.GetString(response);
        return responseData;
    }

 

    public string GetToken(string username, string password)

    {

        var data = new NameValueCollection();

        data["username"] = Username;

        data["password"] = Password;

        data["referer"] = "https://domain.local/portal";

        data["f"] = "json";

 

        TokenInfo x = JsonConvert.DeserializeObject<TokenInfo>(_getResponse(data, "https://domain.local/portal/sharing/rest/generateToken")); -> Here we have the 401 error.

        return x.token; ;

    }

 

    private organizationInformation _getOrgInfo(string token)

    {

        var data = new NameValueCollection();

        data["token"] = token;

        data["f"] = "json";

 

        organizationInformation x = JsonConvert.DeserializeObject<organizationInformation>(_getResponse(data, "https://domain.local/portal/sharing/rest/portals/self")); -> Here we have the 401 error.

        return x;

    }

 

    private string _getResponse(NameValueCollection data, string url)

    {

        string responseData;

        var webClient = new WebClient();

        var response = webClient.UploadValues(url, data); -> Here we have the 401 error.

        responseData = System.Text.Encoding.UTF8.GetString(response);

        return responseData;

    }

 

Regards.

Outcomes