Bigcommerce Authentication code

时间秒杀一切 提交于 2019-12-11 06:49:52

问题


How to get Authentication code ?

I am using https://login.bigcommerce.com/oauth2 url and passing client_id={0}&redirect_uri={1}&response_type=code{2}{3} in get method, but it gives me error "The page you were looking for doesn't exist."

I know after getting Authentication code I can generate token. But first step is no tclear how to get Authentication code using login page?


回答1:


I just went through this oauth token issue and the docs haven't been much help, but once I got going I finally managed to get the app setup by creating my SSL callback page locally on my server. Once I specified that URL in the app settings I was all set. The caveat being I had to do perform the 'install' from the server itself since it wasn't a public URL while logged into BC as the store owner. I was then able to get the temporary token from the querystring and post back to https://login.bigcommerce.com/oauth2/token and obtain the permanent token from the response stream.

You have to include your client id, client secret and the request.querystring["code"] value in your post request.

Here's how I obtained the permanent token which will be inside jsonResponse:

string baseURL = "https://login.bigcommerce.com/oauth2/token";
string contentType = "application/x-www-form-urlencoded";
string callbackURL = <your SSL callback URL>

HttpWebRequest req = WebRequest.CreateHttp(baseURL);
req.AllowAutoRedirect = true;
req.ContentType = contentType;
req.Method = "POST";

//Build POST content body
StringBuilder sb = new StringBuilder();
sb.AppendFormat("client_id={0}", clientID);
sb.AppendFormat("&client_secret={0}", clientSecret);
sb.AppendFormat("&code={0}", tempToken);
sb.AppendFormat("&scope={0}", scopes);
sb.AppendFormat("&grant_type=authorization_code");
sb.AppendFormat("&redirect_uri={0}", callbackURL);
sb.AppendFormat("&context={0}", storeContext);

//Convert the content to byte array and set content length
string contentString = sb.ToString();
byte[] postData = Encoding.UTF8.GetBytes(contentString);
req.ContentLength = postData.Length;

//Send the data to login server
using (Stream stream = req.GetRequestStream())
{
    stream.Write(postData, 0, postData.Length);
    stream.Flush();
    stream.Close();
}

//Get the request response object
WebResponse resp = req.GetResponse();

//Read the contents of the response
StreamReader sr = new StreamReader(resp.GetResponseStream());
string jsonResponse = sr.ReadToEnd();



回答2:


If you're using something similar to my approach shown above, capture the temporary token during the page_load event of the aspx page defined in your callback URL by reading the value of request.querystring["code"]. You can find your store hash within the store's control panel, one location being legacy API accounts if I recall correctly. HTH.



来源:https://stackoverflow.com/questions/23897730/bigcommerce-authentication-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!