RE: External Auth 2.0
"(WalzCraft) Jerry Forss" <[email protected]>
| Newsgroups | gmane.comp.lang.as400.rpg |
|---|---|
| Message-ID | <[email protected]> |
BTW - The URL its using is https://login.microsoftonline.com/....../oauth2/v2.0/token -----Original Message----- From: RPG400-L <rpg400-l-bounces-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org> On Behalf Of (WalzCraft) Jerry Forss Sent: Tuesday, October 14, 2025 10:54 AM To: RPG programming on IBM i <[email protected]> Subject: External Auth 2.0 CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. Hi All I am trying to build a new API to call TForce for shipping requests that uses Auth 2.0. I have done this in the past for FedEx and works but having issues with TForce. I can get the access token in Postman but is failing when I try from my RPG pgm. I am sure it's just something basic I am not understanding. Postman request Authorization Auth Type 2.0 Body client_id What we got for TForce client_secret What we got for TForce scope What we got for TForce grant_type client_credentials Works fine getting token My RPG code // ==================================================================================== // Prototype SetTokenHeader // ==================================================================================== Dcl-Proc SetTokenHeader; // ---------------------------------------------------------------------------------- // Input Parameters // ---------------------------------------------------------------------------------- Dcl-pi *N; Headers VarChar(2000); End-pi; // ---------------------------------------------------------------------------------- // Local Parameters // ---------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------- // Data Structures // ---------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------- // Mainline // ---------------------------------------------------------------------------------- Headers = 'application/x-www-form-urlencoded' + CRLF; End-Proc; // ==================================================================================== // Prototype CreateToken - Generate Token // ==================================================================================== Dcl-Proc CreateToken; // ---------------------------------------------------------------------------------- // Input Parameters // ---------------------------------------------------------------------------------- // Dcl-pi *n; // Token VarChar(100); // End-pi; // ---------------------------------------------------------------------------------- // Local Parameters // ---------------------------------------------------------------------------------- Dcl-S FormData Varchar(1000); // ---------------------------------------------------------------------------------- // Data Structures // ---------------------------------------------------------------------------------- // Token Response From API Call Dcl-ds TokenResponse Qualified; access_token VarChar(2000); token_type Char(20); expires_in Packed(7 : 0); scope Char(20); End-ds; // ---------------------------------------------------------------------------------- // Mainline // ---------------------------------------------------------------------------------- ResponseFile = %Trim(Path) + 'TForce_Token_Resp.json'; Rc = http_xproc(HTTP_POINT_ADDL_HEADER : %paddr(SetTokenHeader)); FormData = 'grant_type=client_credentials' + '&client_id=' + %Trim(ClientID) + '&client_secret=' + %Trim(APIKeyLive) + '&scope=' + %Trim(APIScope); rc = http_req('POST' : APITokenURL : ResponseFile : *omit : *omit : FormData : 'application/x-www-form-urlencoded'); Fails with RC of 400 Response json !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> <HTML><HEAD><TITLE>Bad Request</TITLE> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD> <BODY><h2>Bad Request - Invalid Header</h2> <hr><p>HTTP Error 400. The request has an invalid header name.</p> </BODY></HTML> Subject to Change Notice: WalzCraft reserves the right to improve designs, and to change specifications without notice. Confidentiality Notice: This message and any attachments may contain confidential and privileged information that is protected by law. The information contained herein is transmitted for the sole use of the intended recipient(s) and should "only" pertain to "WalzCraft" company matters. If you are not the intended recipient or designated agent of the recipient of such information, you are hereby notified that any use, dissemination, copying or retention of this email or the information contained herein is strictly prohibited and may subject you to penalties under federal and/or state law. If you received this email in error, please notify the sender immediately and permanently delete this email. Thank You WalzCraft PO Box 1748 La Crosse, WI, 54602-1748 www.walzcraft.com<http://www.walzcraft.com> Phone: 1-800-237-1326 -- This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: [email protected] To subscribe, unsubscribe, or change list options, visit: https://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l. Please contact support-FMtJrHiV//lnDLsaKlm4mFaTQe2KTcn/@public.gmane.org for any subscription related questions. Subject to Change Notice: WalzCraft reserves the right to improve designs, and to change specifications without notice. Confidentiality Notice: This message and any attachments may contain confidential and privileged information that is protected by law. The information contained herein is transmitted for the sole use of the intended recipient(s) and should "only" pertain to "WalzCraft" company matters. If you are not the intended recipient or designated agent of the recipient of such information, you are hereby notified that any use, dissemination, copying or retention of this email or the information contained herein is strictly prohibited and may subject you to penalties under federal and/or state law. If you received this email in error, please notify the sender immediately and permanently delete this email. Thank You WalzCraft PO Box 1748 La Crosse, WI, 54602-1748 www.walzcraft.com<http://www.walzcraft.com> Phone: 1-800-237-1326 -- This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: [email protected] To subscribe, unsubscribe, or change list options, visit: https://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l. Please contact support-FMtJrHiV//lnDLsaKlm4mFaTQe2KTcn/@public.gmane.org for any subscription related questions.