[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Posting Requests To Microsoft Azure



   Hi Charles
   Thanks very much for this info. It's reassuring that I can get the
   authorisation token via a HTTP post. I don't know c#, so I'm guessing
   that the crucial bit of David's code is:
   var body = await HttpPost(tenantId, payload);
   return body.access_token;
   I can see no reference to tenantId in the code - is this the URL I post
   the request to? I know this isn't your code, just wondered whether the
   answer was more obvious to you...
   Thanks,
   Paul

   On 31/03/2016 20:49, Charles Wilt wrote:

   It should be doable in RPG...
   But I don't know that anyone on the list has done it.�  What you want
   to do is look around the web for code showing how to access� Azure
   services from other languages...
   Or even without using the library MS provides.
   I found this:
   [1][1]http://blog.davidebbo.com/2015/12/calling-arm-using-plain-rest.html
   The sample code linked to in the
   article,� [2][2]https://github.com/davidebbo/AzureWebsitesSamples/blob/mas
   ter/HttpClientSample/AuthenticationHelpers.cs
   Has the following:
   �  �  �  �  const string ARMResource =
   "[3][3]https://management.core.windows.net/";;
   �  �  �  �  const string TokenEndpoint =
   "[4][4]https://login.windows.net/{0}/oauth2/token";;
   �  �  �  �  const string SPNPayload =
   "resource={0}&client_id={1}&grant_type=client_credentials&client_secret
   ={2}";
   �  �  �  �  public static async Task<string> AcquireTokenBySPN(string
   tenantId, string clientId, string clientSecret)
   �  �  �  �  {
   �  �  �  �  �  �  var payload = String.Format(SPNPayload,
   �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
   WebUtility.UrlEncode(ARMResource),
   �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
   WebUtility.UrlEncode(clientId),
   �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �  �
   WebUtility.UrlEncode(clientSecret));
   �  �  �  �  �  �  var body = await HttpPost(tenantId, payload);
   �  �  �  �  �  �  return body.access_token;
   �  �  �  �  }
   So we know that getting a token just requires a properly formatted HTTP
   POST.
   Looks MS provides the source not only for the .NET ADAL library but for
   other languages including Java and Node.js.
   [5][5]https://azure.microsoft.com/en-us/documentation/articles/active-dire
   ctory-authentication-libraries/
   Digging into those should provide everything you need to figure out how
   the POST need to be sent.
   Though a quicker and easier solution would be to use Java or Node.js
   from the i.
   Let us know how it turns out.
   Charles

   On Thu, Mar 31, 2016 at 8:21 AM, Paul Park [6]<[6]parkp@xxxxxxxxxx> wrote:

     Hi
     I have a new requirement to post requests to a REST web service
     hosted on a Microsoft Azure platform.�  I've had success in the past
     using Scott's HTTPAPI service program to post XML requests to a SOAP
     service, and I believe that posting to REST should be no problem
     either.
     I have two stumbling blocks that I know of, though, and they are
     shown on a page that explains how to make requests to the new
     service -
     [7][7]https://msdn.microsoft.com/en-us/library/azure/mt428036.aspx.
     I'll list them here:
     1) "To make a data request to the Data Catalog REST service, you
     need to supply an access token. In a .NET client app, you use the
     Windows Azure Authentication Library (ADAL) to get an access token."
     string authorityUri =
     "[8][8]https://login.windows.net/common/oauth2/authorize";;
     �  AuthenticationContext authContext = new
     AuthenticationContext(authorityUri);
     �  AuthenticationResult token =
     authContext.AcquireToken(resourceUri, clientId, new
     Uri(redirectUri), PromptBehavior.RefreshSession);
     2) "After you get an access token from Active Directory (AAD), you
     use the token to make a web request to the Data Catalog REST API. To
     create a Data Catalog REST web request, you add an access token to a
     request header."
     I have no idea how to tackle step 1 - get an access token. The
     example is .NET, and I suspect I can't do this.
     Step 2 - add the token to a request header might be possible, as
     I've seen examples that use http_setauth to pass a user id and
     password. Can I use http_setauth to send an access token?
     I've already prepared my boss for disappointment on this, but I need
     to know: is there a way to do step 1 in RPG?
     Thanks for any input.
     Paul
     Enterprise Software Systems.
     Company No 3374336. Registered in England,
     Registered Office: Enterprise House, Pacific Road
     Altrincham, Cheshire, WA14 5EN
     The information in this email is confidential and may be legally
     privileged. It is intended solely for the addressee. Access to this
     email
     by anyone else is unauthorized. If you are not the intended
     recipient, any
     disclosure, copying, distribution or any action taken or omitted to
     be
     taken in reliance on it, is prohibited and may be unlawful. If you
     are not
     the intended addressee please contact the sender and dispose of this
     e-mail.
     --------------------------------------------------------------------
     ---
     This is the FTPAPI mailing list.�  To unsubscribe, please go to:
     [9][9]http://www.scottklement.com/mailman/listinfo/ftpapi
     --------------------------------------------------------------------
     ---

References

   1. [10]http://blog.davidebbo.com/2015/12/calling-arm-using-plain-rest.html
   2. [11]https://github.com/davidebbo/AzureWebsitesSamples/blob/master/HttpClie
ntSample/AuthenticationHelpers.cs
   3. [12]https://management.core.windows.net/
   4. [13]https://login.windows.net/{0}/oauth2/token
   5. [14]https://azure.microsoft.com/en-us/documentation/articles/active-direct
ory-authentication-libraries/
   6. [15]mailto:parkp@xxxxxxxxxx
   7. [16]https://msdn.microsoft.com/en-us/library/azure/mt428036.aspx
   8. [17]https://login.windows.net/common/oauth2/authorize
   9. [18]http://www.scottklement.com/mailman/listinfo/ftpapi


-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
[19]http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------

   --
   Paul Park
   Application Developer
   enterprise SOFTWARE
   Registered Office: Enterprise House | Pacific Road | Atlantic Office
   Park | Altrincham | Cheshire | WA14 5EN
   Office: 0161 925 2400 | email: [20]parkp@xxxxxxxxxx | Web:
   [21]www.essl.co.uk
     __________________________________________________________________

   Enterprise Software Systems.
   Company No 3374336. Registered in England,
   Registered Office: Enterprise House, Pacific Road
   Altrincham, Cheshire, WA14 5EN
   The information in this email is confidential and may be legally
   privileged. It is intended solely for the addressee. Access to this ema
   il
   by anyone else is unauthorized. If you are not the intended recipient,
   any
   disclosure, copying, distribution or any action taken or omitted to be
   taken in reliance on it, is prohibited and may be unlawful. If you are
   not
   the intended addressee please contact the sender and dispose of this
   e-mail.

References

   Visible links
   1. http://blog.davidebbo.com/2015/12/calling-arm-using-plain-rest.html
   2. https://github.com/davidebbo/AzureWebsitesSamples/blob/mas
   3. https://management.core.windows.net/
   4. https://login.windows.net/
   5. https://azure.microsoft.com/en-us/documentation/articles/active-dire
   6. mailto:[6]parkp@xxxxxxxxxx
   7. https://msdn.microsoft.com/en-us/library/azure/mt428036.aspx
   8. https://login.windows.net/common/oauth2/authorize
   9. http://www.scottklement.com/mailman/listinfo/ftpapi
  10. http://blog.davidebbo.com/2015/12/calling-arm-using-plain-rest.html
  11. https://github.com/davidebbo/AzureWebsitesSamples/blob/master/HttpClientSample/AuthenticationHelpers.cs
  12. https://management.core.windows.net/
  13. https://login.windows.net/
  14. https://azure.microsoft.com/en-us/documentation/articles/active-directory-authentication-libraries/
  15. mailto:parkp@xxxxxxxxxx
  16. https://msdn.microsoft.com/en-us/library/azure/mt428036.aspx
  17. https://login.windows.net/common/oauth2/authorize
  18. http://www.scottklement.com/mailman/listinfo/ftpapi
  19. http://www.scottklement.com/mailman/listinfo/ftpapi
  20. mailto:parkp@xxxxxxxxxx
  21. http://www.essl.co.uk/

   Hidden links:
  22. mailto:parkp@xxxxxxxxxx
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------