<?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: JSL / JMP 17: OAuth apparently generates invalid request in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/847345#M102207</link>
    <description>&lt;P&gt;Small (but important) correction: it seems my approach only works with JMP 18, not with JMP 17.&lt;BR /&gt;Apparently, "Authorization Method" was introduced only in JMP 18. When trying to use the approach in JMP 17, I get:&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Unrecognized message in access or evaluation of 'Authentication Method' , Authentication Method( "BASIC" ) /*###*/&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I re-checked the documentation:&lt;BR /&gt;- the JMP 17 docs contain no mention of "Authentication Method" whatsoever&lt;BR /&gt;- the JMP 18 docs contain one &lt;A href="https://www.jmp.com/support/help/en/18.0/#page/jmp/pi-server-messages.shtml" target="_self"&gt;example of "Authentication Method" in a PI call&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;(I hadn't noticed this before because apparently, the token from my JMP 18 tests was stored inside the JMP file / data table, and therefore, JMP 17 happily used the old token even though its own attempt to obtain a new one failed)&lt;/P&gt;</description>
    <pubDate>Tue, 11 Mar 2025 15:15:16 GMT</pubDate>
    <dc:creator>inreoh</dc:creator>
    <dc:date>2025-03-11T15:15:16Z</dc:date>
    <item>
      <title>JSL / JMP 17: OAuth apparently generates invalid request</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/836077#M101326</link>
      <description>&lt;P&gt;I'm currently trying to obtain an OAuth2 token to authenticate for an external service (Snowflake database), but I'm running into some problems with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;According to &lt;A href="https://www.jmp.com/support/help/en/17.0/index.shtml#page/jmp/resource-owner-grant.shtml#" target="_self"&gt;the documentation&lt;/A&gt;, this is supposed to work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;oauth2_token = New OAuth2 Token(&lt;BR /&gt;  User( username ),&lt;BR /&gt;  Password( password),&lt;BR /&gt;  Client ID( client_id ),&lt;BR /&gt;  Client Secret( client_secret ),&lt;BR /&gt;  Token URL( "http://localhost:8008" ),&lt;BR /&gt;  Grant Type("password"),&lt;BR /&gt;  Scope("session:role-any")&lt;BR /&gt;);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, whenever I run this, I get back an HTTP/1.1 400 Bad Request INVALID_REQUEST:INVALID_REQUESTDESCRIPTION&lt;BR /&gt;&lt;BR /&gt;To debug this, I started a locally running HTTP echo server and sent requests from Python (working code, verified with real OAuth2 server) and JMP, and I got back this:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Python&lt;/STRONG&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;127.0.0.1 - - [05/Feb/2025 13:36:00] "POST / HTTP/1.1" 200 -&lt;BR /&gt;Host: localhost:8008&lt;BR /&gt;User-Agent: python-requests/2.32.3&lt;BR /&gt;Accept-Encoding: gzip, deflate&lt;BR /&gt;Accept: */*&lt;BR /&gt;Connection: keep-alive&lt;BR /&gt;Content-Length: 91&lt;BR /&gt;Content-Type: application/x-www-form-urlencoded&lt;BR /&gt;Authorization: Basic &amp;lt;redacted&amp;gt;=&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;grant_type=password&amp;amp;username=&amp;lt;redacted&amp;gt;&amp;amp;password=&amp;lt;redacted&amp;gt;&amp;amp;scope=session%3Arole-any&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;JMP 17&lt;/STRONG&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;127.0.0.1 - - [05/Feb/2025 13:36:56] "POST / HTTP/1.1" 200 -&lt;BR /&gt;Host: localhost:8008&lt;BR /&gt;User-Agent: libcurl-agent/1.0 (Windows NT 10.0.22631;x64)&lt;BR /&gt;Accept: */*&lt;BR /&gt;Content-Length: 102&lt;BR /&gt;Content-Type: application/x-www-form-urlencoded&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;client_id=&amp;lt;redacted&amp;gt;&amp;amp;redirect_uri=&amp;amp;response_type=token&amp;amp;scope=&amp;amp;state=&amp;lt;redacted&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;As you can see, there's no Authorization header, and also, most of the request parameters (grant type, username, password, scope) are missing.&lt;BR /&gt;To me, it looks like JMP generates a bogus request, and therefore, the communication with the server fails. Is this assumption correct? Or am I doing something wrong?&lt;BR /&gt;&lt;BR /&gt;Any help would be highly appreciated.&lt;BR /&gt;&lt;BR /&gt;Kind regards&lt;BR /&gt;Frank&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2025 13:47:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/836077#M101326</guid>
      <dc:creator>inreoh</dc:creator>
      <dc:date>2025-02-05T13:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: JSL / JMP 17: OAuth apparently generates invalid request</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/836634#M101344</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/5036"&gt;@bryan_boone&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure if these links will be helpful but &lt;LI-MESSAGE title="Integrating Google Drive with JMP using HTTP Request" uid="545688" url="https://community.jmp.com/t5/JMP-Scripts/Integrating-Google-Drive-with-JMP-using-HTTP-Request/m-p/545688#U545688" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;might give some ideas. Also check out Get Authorization Header + New OAuth2 from Scripting Index (bryan mentioned these here &lt;A href="https://community.jmp.com/t5/Discussions/Open-file-from-private-github-repository-authentication-needed/m-p/777304/highlight/true#M95860" target="_blank"&gt;https://community.jmp.com/t5/Discussions/Open-file-from-private-github-repository-authentication-needed/m-p/777304/highlight/true#M95860&lt;/A&gt;). There is also a bit more documentation in JSL Syntax Reference but no idea if this helpful at all &lt;A href="https://www.jmp.com/support/help/en/18.1/#page/jmp/utility-functions.shtml?os=win&amp;amp;source=application#ww7957559" target="_blank"&gt;https://www.jmp.com/support/help/en/18.1/#page/jmp/utility-functions.shtml?os=win&amp;amp;source=application#ww7957559&lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 12:38:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/836634#M101344</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-02-06T12:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: JSL / JMP 17: OAuth apparently generates invalid request</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/836712#M101350</link>
      <description>&lt;P&gt;Yes,&lt;/P&gt;
&lt;P&gt;New OAuth2&lt;/P&gt;
&lt;P&gt;is the way to go. I look to see if I can alias New OAuth2 Token to it.&lt;/P&gt;
&lt;P&gt;If not, I'll deprecate&amp;nbsp;New OAuth2 Token.&lt;/P&gt;
&lt;P&gt;New OAuth2 does all the browser handshaking for you.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 15:47:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/836712#M101350</guid>
      <dc:creator>bryan_boone</dc:creator>
      <dc:date>2025-02-06T15:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: JSL / JMP 17: OAuth apparently generates invalid request</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/837487#M101389</link>
      <description>&lt;P&gt;Thanks, New OAuth2() looks much better. I was successfully able to obtain a Refresh token with the "Client Credentials" flow.&lt;BR /&gt;&lt;BR /&gt;However, I'm struggling with getting the Password flow to work. My current code looks like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;client_id = "&amp;lt;redacted&amp;gt;";
client_secret = "&amp;lt;redacted&amp;gt;";
token_url = "https://someurl/token";
auth_url = "https://someurl/auth";
username = "&amp;lt;redacted&amp;gt;";
password = "&amp;lt;redacted&amp;gt;";
grant_type = "password";
scope = "session:role-any";
auth_fields = [=&amp;gt; ];
token_fields = [=&amp;gt; ];
                                          
oauth2 = New OAuth2();
oauth2 &amp;lt;&amp;lt; Grant Type( "Password" );
oauth2 &amp;lt;&amp;lt; Auth URL( auth_url );
oauth2 &amp;lt;&amp;lt; Token URL( token_url );
                                     
oauth2 &amp;lt;&amp;lt; Username(username);
oauth2 &amp;lt;&amp;lt; Password(password);                                     
                                          
auth_fields["scope"] = scope;
auth_fields["client_id"] = client_id;
token_fields["client_secret"] = client_secret;
                                          
oauth2 &amp;lt;&amp;lt; Auth Fields( auth_fields );
oauth2 &amp;lt;&amp;lt; Token Fields( token_fields );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, this results in HTTP/1.1 401 Unauthorized.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;For comparison, here's a working example in Python:&lt;/P&gt;&lt;PRE&gt;def get_token(username: str, password: str, client_secret: str) -&amp;gt; str:
    client_auth = requests.auth.HTTPBasicAuth(CLIENT_ID, client_secret)
    post_data = {
        "grant_type": "password",
        "username": username,
        "password": password,
        "scope": "session:role-any",
    }
    response = requests.post(TOKEN_URL, auth=client_auth, data=post_data)
    token_json = response.json()
    print(f"Got token: {token_json}")
    return token_json["access_token"]&lt;/PRE&gt;&lt;P&gt;I guess that somehow, JMP doesn't establish the HTTP Basic auth with client_id / client_secret. What am I doing wrong?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2025 14:05:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/837487#M101389</guid>
      <dc:creator>inreoh</dc:creator>
      <dc:date>2025-02-07T14:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: JSL / JMP 17: OAuth apparently generates invalid request</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/837538#M101393</link>
      <description>&lt;P&gt;I think you are talking about:&lt;BR /&gt;&lt;A href="https://oauth.net/2/grant-types/password/" target="_blank"&gt;https://oauth.net/2/grant-types/password/&lt;/A&gt;&lt;BR /&gt;This discussion (on the reference) says there's a move away from this.&lt;/P&gt;
&lt;P&gt;You can probably do it all with HTTPRequest (without New OAuth2) since there is no need to prompt using password grant type (ie, it goes directly against the token URL)&lt;/P&gt;
&lt;P&gt;The equivalent JSL (to the python) I believe looks like this, but I can't test it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;client_id = "&amp;lt;redacted&amp;gt;";
client_secret = "&amp;lt;redacted&amp;gt;";
token_url = "https://someurl/token";
username = "&amp;lt;redacted&amp;gt;";
password = "&amp;lt;redacted&amp;gt;";
grant_type = "password";
scope = "session:role-any";

payload =[=&amp;gt;];
payload["grant_type"] = "password";
payload["username"] = username;
payload["password"] = password;
payload["scope"] = scope;

request = New HTTP Request(
	URL(token_url),
	Username(client_id),
	Passwordlient_id),
	JSON(payload)
);

data = request &amp;lt;&amp;lt; Send();
json = ParseJSON(data);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2025 15:32:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/837538#M101393</guid>
      <dc:creator>bryan_boone</dc:creator>
      <dc:date>2025-02-07T15:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: JSL / JMP 17: OAuth apparently generates invalid request</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/839808#M101472</link>
      <description>&lt;P&gt;With some fiddling, I got it to work; key changes from your suggestion:&lt;/P&gt;&lt;P&gt;- include Basic Auth&lt;/P&gt;&lt;P&gt;- use Form encoding instead of JSON (not 100% sure why JSON didn't work, though)&lt;BR /&gt;&lt;BR /&gt;Working example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;client_id = "&amp;lt;redacted&amp;gt;";
client_secret = "&amp;lt;redacted&amp;gt;";
token_url = "https://someurl/token";
username = "&amp;lt;redacted&amp;gt;";
password = "&amp;lt;redacted&amp;gt;";
grant_type = "password";
scope = "session:role-any";

request = New HTTP Request(
    Method("POST"),
	URL(token_url),
	Username(client_id),
	Password(client_secret),
	Form(
	  Fields([[
	         "grant_type" =&amp;gt; grant_type, 
	         "username" =&amp;gt; username, 
	         "password" =&amp;gt; password,
	         "scope" =&amp;gt; scope
	         ]]
	         )
	)
);

request &amp;lt;&amp;lt; Authentication Method( "BASIC" );

data = request &amp;lt;&amp;lt; Send();
json = ParseJSON(data);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;For the time being, that's ok (we're using a technical user, so no need to get the user's personal password), but we'll definitely look into more secure approaches.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2025 15:22:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/839808#M101472</guid>
      <dc:creator>inreoh</dc:creator>
      <dc:date>2025-02-11T15:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: JSL / JMP 17: OAuth apparently generates invalid request</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/839857#M101484</link>
      <description>&lt;P&gt;Great find! I wasn't quite sure which 17 I introduced Authorization Method (maybe a maintenance?)&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2025 17:35:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/839857#M101484</guid>
      <dc:creator>bryan_boone</dc:creator>
      <dc:date>2025-02-11T17:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: JSL / JMP 17: OAuth apparently generates invalid request</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/847345#M102207</link>
      <description>&lt;P&gt;Small (but important) correction: it seems my approach only works with JMP 18, not with JMP 17.&lt;BR /&gt;Apparently, "Authorization Method" was introduced only in JMP 18. When trying to use the approach in JMP 17, I get:&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Unrecognized message in access or evaluation of 'Authentication Method' , Authentication Method( "BASIC" ) /*###*/&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I re-checked the documentation:&lt;BR /&gt;- the JMP 17 docs contain no mention of "Authentication Method" whatsoever&lt;BR /&gt;- the JMP 18 docs contain one &lt;A href="https://www.jmp.com/support/help/en/18.0/#page/jmp/pi-server-messages.shtml" target="_self"&gt;example of "Authentication Method" in a PI call&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;(I hadn't noticed this before because apparently, the token from my JMP 18 tests was stored inside the JMP file / data table, and therefore, JMP 17 happily used the old token even though its own attempt to obtain a new one failed)&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 15:15:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-JMP-17-OAuth-apparently-generates-invalid-request/m-p/847345#M102207</guid>
      <dc:creator>inreoh</dc:creator>
      <dc:date>2025-03-11T15:15:16Z</dc:date>
    </item>
  </channel>
</rss>

