Reputation: 21
I'm trying to access Microsoft LiveConnect from a Java webapp. And I have a problem of getting tokens.
The problem is following: I followed the Authorization code grant flow as indicated in http://msdn.microsoft.com/en-us/library/live/hh243647.aspx#authcodegrant
LiveConnect does redirect user-agent (browser) to my server with a URL of the following format
http://contoso.com/Callback.htm?code=AUTHORIZATION_CODE
then my web-app issues a REST (POST request) to LiveConnect with the following format
POST https://login.live.com/oauth20_token.srf
Content-type: application/x-www-form-urlencoded
client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&client_secret=CLIENT_SECRET&code=AUTHORIZATION_CODE&grant_type=authorization_code
Instead of returning some meaningful data, LiveConnect return a html page contains some irrelevant information, like this
<html>
...
<body class="modern" onLoad="BodyLoad()">
<div class="header" id="i0272"><span>Microsoft account</span></div>
<div class="content">
<div style="padding:15px 0 0 0;font-size:1px;"> </div>
<h1 class="css0046">We're unable to complete your request</h1>
<p class="css0005">Microsoft account is experiencing technical problems. Please try again later.</p></div>
I also post here the Java code that involves with the REST api
URL urlConnection = new URL(this.url);
HttpURLConnection connection = (HttpURLConnection) urlConnection.openConnection();
OutputStream outputStream = null;
try {
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setReadTimeout(DEFAULT_READ_TIMEOUT_IN_MS);
connection.setUseCaches(false);
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + data.getBytes("UTF-8").length);
for(String key : params.keySet()){
connection.setRequestProperty(key, params.get(key));
}
executed.set(true);
connection.connect();
outputStream = connection.getOutputStream();
//outputStream.write("\r\n".getBytes("UTF-8"));
outputStream.write(data.getBytes("UTF-8"));
outputStream.flush();
httpInputStream = connection.getResponseCode() != HTTP_OK ?
connection.getErrorStream() :
connection.getInputStream();
return new Response(connection.getResponseCode(), Utils.fromInputStream(httpInputStream));
Upvotes: 2
Views: 1264
Reputation:
The Url of the page with your duff content might be more meaningful. Mine has this:
https://login.live.com/err.srf?lc=2057#error=invalid_request&error_description=The%20provided%20value%20for%20the%20input%20parameter%20%27redirect_uri%27%20is%20not%20valid.%20The%20expected%20value%20is%20%27https://login.live.com/oauth20_desktop.srf%27%20or%20a%20URL%20which%20matches%20the%20redirect%20URI%20registered%20for%20this%20client%20application.&state=redirect_type%3dauth%26display%3dpage%26request_ts%3d1412608929255%26response_method%3dcookie%26secure_cookie%3dfalse
Make sure that your app and the OneDrive Dev Center Redirect URLs both have exactly the same url, ie:
http://contoso.com/Callback.htm
which includes the page.
I got the same bland error page, with the URL above, when my URL in OneDrive Dev Center did not include the page. Set the redirect URL in :
https://account.live.com/developers/applications
Log in and got to the Dashboard > My Apps > YourAppName > API Settings
When developing you also need to redirect the domain (contoso.com) to your local IIS IP address (127.0.0.1) as described here: "http://msdn.microsoft.com/en-us/library/live/hh826547.aspx"
Hope this helps someone (I know it is rather late)
Upvotes: 1