To simplify the oAuth flow, we recommend to use the RestSharp library.
Step 1 - obtain accessToken from BellaDati REST API
Configure the oAuth settings on your domain detail page. See REST API.
Dim lcUrl As String = "http://127.0.0.1" Dim lcKey As String = "belladati_key" Dim lcToken As String = "" Dim accessUrl As String = lcUrl + "oauth/accessToken" Dim lcSuperUserId As String = "user" Dim lcSuperUserPassword As String = "password" Dim loClient As New RestClient(lcUrl) Dim lorequest As RestRequest Dim loRtn As IRestResponse lorequest = New RestRequest("oauth/accessToken", Method.POST) lorequest.AddParameter("oauth_consumer_key", lcKey) lorequest.AddParameter("oauth_nonce", Guid.NewGuid().ToString()) lorequest.AddParameter("oauth_timestamp", GetTimeStamp) lorequest.AddParameter("x_auth_username", lcSuperUserId) lorequest.AddParameter("x_auth_password", lcSuperUserPassword) loRtn = loClient.Execute(lorequest) If loRtn.StatusDescription.ToUpper.Equals("OK") Then lcToken = loRtn.Content.Split("&")(0).Split("=")(1).Trim Else Throw loRtn.ErrorException End If lcheader = "OAuth realm=""{0}"", oauth_consumer_key=""{1}"", oauth_token=""{2}"",oauth_timestamp=""{3}"", oauth_nonce=""{4}""" lcheader = String.Format(lcheader, lcUrl.Trim + "/", lcKey.Trim, lcToken.Trim, GetTimeStamp(), Guid.NewGuid.ToString) poRequest = New RestRequest("api/users/adminRnD@RnD/requests", Method.POST) poRequest.AddHeader("Authorization", lcheader) With poRequest .AddParameter("username", "adminRnD@RnD") .AddParameter("request_type", "LOGIN_UNATTENDED") End With
Step 2 - create unattended login request and get request_id and request_code
Dim loClient As New RestClient(lcUrl) Dim linkId As StringDim requestLink As String Dim loRtn As IRestResponseDim loRequests As String() loRtn = loClient.Execute(poRequest) linkId = loRtn.Content loRequests = linkId.Split(";")
Step 3 - generate login link with request_id and request_code
requestLink = lcUrl + "user/processRequest/" + loRequests(0).Trim + "/" + loRequests(1).Trim
Step 4 - execute XMLHttpRequest using the generated link
Don't forget to configure the CORS filter on BellaDati settings page.
$.ajax({ url: link, xhrFields: { withCredentials: true }, success: console.log("Success"), error: console.log("Error") });
Overview
Content Tools