Box API always returns invalid grant_type parameter on obtaining access token

后端 未结 4 1190
北海茫月
北海茫月 2020-12-21 23:26

I\'m writing my own Box SDK for WP8 to make the most out of Tasks. I am having trouble obtaining an access token. I always get this as a return:

{\"error\":\         


        
相关标签:
4条回答
  • 2020-12-22 00:13

    I think that including the redirect_uri in your request body could be complicating things, particularly because it looks to be set to an invalid value (https://CloudBoxWP8) You might resolve this by setting your app to handle a custom protocol (cloudboxwp8://) and pre-configuring Box to redirect to that when the token is granted.

    1. Register a custom protocol for your WP8 app. For example, cloudboxwp8.
    2. Augment your WP8 app to handle a request for some endpoint on that protocol. For example, cloudboxwp8://tokengranted. Implement your token handling logic here.
    3. Edit your Box application and browse to the OAuth2 paramters section (via Manage a Box Application => Edit Application)
    4. In the redirect_uri field, set the value to the custom protocol and endpoint from step 2. Save your changes.
    5. Remove the redirect_uri from your request body and try your request again.
    0 讨论(0)
  • 2020-12-22 00:26

    The request/response would be helpful. It looks like you are UrlEncoding the entire query string instead of just each value. Which would be submitted to us as: grant_type%3Dauthorization_code%26code%3Dxyz%26client_id%3Dxyz%26client_secret%3Dxyz%26redirect_uri%3Dxyz

    Instead of: grant_type=authorization_code&code=xyz&client_id=xyz&client_secret=xyz&redirect_uri=xyz

    0 讨论(0)
  • 2020-12-22 00:26

    in Windows phone 8.1 WinRT

    Dictionary<string, string> contentList = new Dictionary<string, string>();
    
    contentList.Add("code", code);
    contentList.Add("client_id", client_id);
    contentList.Add("client_secret", clientSecret);
    contentList.Add("redirect_uri", redirectUri);
    contentList.Add("grant_type", "authorization_code");
    
    FormUrlEncodedContent content = new FormUrlEncodedContent(contentList);
    
    var response = await client.PostAsync(baseURL, content);
    YouTubeAutenticationResponse res =       JsonConvert.DeserializeObject<YouTubeAutenticationResponse>(await     response.Content.ReadAsStringAsync());
    
    public class YouTubeAutenticationResponse
    {
        [JsonProperty("access_token")]
        public string AccessToken { get; set; }
        [JsonProperty("token_type")]
        public string TokenType { get; set; }
        [JsonProperty("expires_in")]
        public string ExpiresIn { get; set; }
        [JsonProperty("refresh_token")]
        public string RefreshToken { get; set; }
    }
    
    0 讨论(0)
  • 2020-12-22 00:27

    It's not listed anywhere on the Box API documentation, but the request for retrieving the access token requires the header Content-Type: application/x-www-form-urlencoded

    I was also stuck on this part for a while until I found the answer on StackOverflow. I forget the link to it though.

    0 讨论(0)
提交回复
热议问题