<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SignInToPortal with an SSO. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/signintoportal-with-an-sso/m-p/1303649#M68046</link>
    <description>&lt;P&gt;Is there a reason you aren't just supplying the username and password when you instantiate the GIS object? The api should take care of making sure the authentication and authorization is handled correctly.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Jun 2023 21:59:54 GMT</pubDate>
    <dc:creator>TonyContreras_Frisco_TX</dc:creator>
    <dc:date>2023-06-27T21:59:54Z</dc:date>
    <item>
      <title>SignInToPortal with an SSO.</title>
      <link>https://community.esri.com/t5/python-questions/signintoportal-with-an-sso/m-p/1303526#M68039</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;&lt;P&gt;I am trying to write a script to automate the publishing of web layers and have run into a problem since our organization uses an SSO (Single Sign On).&amp;nbsp; I wrote script to get the SSO token, and login to portal (Below, with all appropriate packages imported).&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;# Gettoken for the Palm Beach County SSO&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;getToken&lt;/SPAN&gt;(&lt;SPAN&gt;portal&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;sso&lt;/SPAN&gt;):&lt;BR /&gt;    &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;'Connecting to portal...&lt;/SPAN&gt;&lt;SPAN&gt;\n&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;)&lt;BR /&gt;    &lt;SPAN&gt;# Get username and password&lt;BR /&gt;&lt;/SPAN&gt;    username = &lt;SPAN&gt;input(str('Enter your SIM username and press Enter: '))&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;   # warnings.simplefilter("ignore", category=getpass.GetPassWarning)&lt;BR /&gt;&lt;/SPAN&gt;    password = &lt;SPAN&gt;getpass.getpass('Enter your SIM password and press Enter: ')&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    payload = {&lt;BR /&gt;        &lt;SPAN&gt;"username"&lt;/SPAN&gt;: username&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;"password"&lt;/SPAN&gt;: password&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;"client"&lt;/SPAN&gt;: &lt;SPAN&gt;"referer"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;"referer"&lt;/SPAN&gt;: &lt;SPAN&gt;portal&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;"expiration"&lt;/SPAN&gt;: &lt;SPAN&gt;"1440"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;"f"&lt;/SPAN&gt;: &lt;SPAN&gt;"json"&lt;BR /&gt;&lt;/SPAN&gt;    }&lt;BR /&gt;&lt;BR /&gt;    response = requests.post(&lt;SPAN&gt;sso&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;data&lt;/SPAN&gt;=payload)&lt;BR /&gt;    token = response.json().get(&lt;SPAN&gt;"access_token"&lt;/SPAN&gt;)&lt;BR /&gt;    &lt;SPAN&gt;return &lt;/SPAN&gt;token&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;#Sign into portal&lt;BR /&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;portalConnect&lt;/SPAN&gt;():   &lt;BR /&gt;   portal_url = &lt;SPAN&gt;'myPortalurl'  #my script has the actual urls for portal and sso here&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;   sso_url = &lt;SPAN&gt;'mySSOurl' &lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;   token = getToken(portal_url&lt;SPAN&gt;, &lt;/SPAN&gt;sso_url)&lt;BR /&gt;   gis = GIS(portal_url&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;token&lt;/SPAN&gt;=token)&lt;BR /&gt;   &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;\n&lt;/SPAN&gt;&lt;SPAN&gt;Connected to: '&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;gis.properties.name)&lt;/PRE&gt;&lt;P&gt;The above code results with:&lt;/P&gt;&lt;P&gt;Connecting to portal...&lt;/P&gt;&lt;P&gt;Connected to: Palm Beach County ArcGIS Enterprise&lt;/P&gt;&lt;P&gt;However, when I actually try to exportTOSDDraft I get&lt;/P&gt;&lt;P&gt;ValueError: Unable to connect to portal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using the arcpy.SignInToPortal and it says 'unable to generate token' but "token" is not a valid parameter for this function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone been successful in publishing a service definition draft to portal when there is an SSO? Or does anyone know how I can do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2023 18:47:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/signintoportal-with-an-sso/m-p/1303526#M68039</guid>
      <dc:creator>AngelaSchirck</dc:creator>
      <dc:date>2023-06-27T18:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: SignInToPortal with an SSO.</title>
      <link>https://community.esri.com/t5/python-questions/signintoportal-with-an-sso/m-p/1303649#M68046</link>
      <description>&lt;P&gt;Is there a reason you aren't just supplying the username and password when you instantiate the GIS object? The api should take care of making sure the authentication and authorization is handled correctly.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2023 21:59:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/signintoportal-with-an-sso/m-p/1303649#M68046</guid>
      <dc:creator>TonyContreras_Frisco_TX</dc:creator>
      <dc:date>2023-06-27T21:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: SignInToPortal with an SSO.</title>
      <link>https://community.esri.com/t5/python-questions/signintoportal-with-an-sso/m-p/1303838#M68054</link>
      <description>&lt;P&gt;It does not. The Username and password are entered in the "get token" function.&amp;nbsp; Reentering them again in the GIS object gives an error.&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;Connecting to portal...&lt;/P&gt;&lt;P&gt;A general error occurred: Could not login. Please ensure you have valid credentials and set your security login question.&lt;BR /&gt;&amp;lt;class 'Exception'&amp;gt;&lt;BR /&gt;Connection to portal failed!&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;When I signin (regularly) I have to purposely click on our SSO link to sign in.&amp;nbsp; If I just use the "regular" signin portal it gives an error.&amp;nbsp; The script above takes me to the PBC SSO and logs in as evident by the "&lt;SPAN&gt;Connected to: Palm Beach County ArcGIS Enterprise" message.&amp;nbsp; The GIS object uses the token where the username and password are entered and connects correctly.&amp;nbsp; The problem is later in the script where I call the&amp;nbsp;exportTOSDDraft function it "thinks" I'm not connected to portal.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AngelaSchirck_0-1687950204926.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/74357iDA6D41361256AAD2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AngelaSchirck_0-1687950204926.png" alt="AngelaSchirck_0-1687950204926.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2023 11:31:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/signintoportal-with-an-sso/m-p/1303838#M68054</guid>
      <dc:creator>AngelaSchirck</dc:creator>
      <dc:date>2023-06-28T11:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: SignInToPortal with an SSO.</title>
      <link>https://community.esri.com/t5/python-questions/signintoportal-with-an-sso/m-p/1303917#M68055</link>
      <description>&lt;P&gt;So, as it turns out the above script does connect to and set active portal.&amp;nbsp; The issue was in the aprx itself which did not also have the active portal set to the one connected to.&amp;nbsp; Setting the active portal in the project resolved the issue.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2023 14:45:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/signintoportal-with-an-sso/m-p/1303917#M68055</guid>
      <dc:creator>AngelaSchirck</dc:creator>
      <dc:date>2023-06-28T14:45:47Z</dc:date>
    </item>
  </channel>
</rss>

