Can't authenticate with Yammer.
I've tried to use socialauth library but without any success.
public void onError(SocialAuthError socialAuthError)
Error log:
org.brickred.socialauth.exception.SocialAuthConfigurationException: Problem in getting Access Token. Application key or Secret key may be wrong.The server running the application should be same that was registered to get the keys.
Could not connect using SocialAuth
I've checked the keys again and both consumer_key and consumer_secret are right.
Even got the issue registered, but seems the project is not supported anymore.
https://code.google.com/p/socialauth/issues/detail?id=385&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary%20Modified
With my own authentication I could get an access token, but could not make any REST-API call. Just getting an error "Unauthorized" (401) all the time.
HTTP params are fine according to docs, got all the cookies, but can't use REST-API.
Any ideas?
Fixed. The problem was in wrong headers placement. I've been setting headers to response handler for loopj async http client, with the method handler.setRequestHeaders(...);, but the right way is to add headers to client - client.addHeader("Authorization", "Bearer " + access_token);
Related
I have the port forwarded, I've checked here:
http://www.canyouseeme.org/
I can get the cookie, however using the this logic(that works for local networks):
Get cookie
Get token using the cookie and authentication
Use token to call WEBAPI actions
The problem is that I cannot even get the token.
I get this error : FileNotFoundException
The same IP, port and link works fine in my browser, making me think there is either a problem with authentication or something with the cookie.
String authorization = "Basic " + new String(android.util.Base64.encode((auth).getBytes(), android.util.Base64.NO_WRAP));
That is then used like this:
connection.setRequestProperty("Authorization", authorization);
The HTTP response is : HEADER FIELDS{null=[HTTP/1.1 400 ERROR], Connection=[keep-alive], Content-Length=[17], Content-Type=[text/html], X-Android-Received-Millis=[1484153865632], X-Android-Response-Source=[NETWORK 400], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1484153865562]}
There shouldnt be an error at this point. I really dont get how it could be a bad request when connecting to a global IP but OK on a local connection.
So my question is. Should I authenticate differently when connecting to a global IP? How? Like always, the documentation is of no help at all.
No idea what was wrong. But setting up a new port at 8080, which could be used as an inside and outside port worked.
I am trying to authenticate the user using oauth2 api from Google. There are 2 platforms, Android and Web. For new users, I am fetching the one-time auth code on the client and sending it to the server on both platforms. Once server receives the code, it is fetching the access token and after that, the user details. The server is able to fetch the token from the one-time auth code sent from Android device, but it is failing for the code sent from Web.
This is my code snippet in JS for fetching one-time auth code..
gauth2.grantOfflineAccess({
'scope': 'profile email',
'redirect_uri': 'postmessage'
}).then(function(e){
if(!e){
// Error
}
else{
console.log('Auth code: '+e.code);
}
});
On server side, this is the POST request that I am doing to fetch the token from one-time code..
post_data = {'code': one_time_code, 'client_id': settings.GOOGLE_OAUTH2_CLIENT_ID, 'client_secret': settings.GOOGLE_OAUTH2_CLIENT_SECRET, 'grant_type': 'authorization_code'}
req = urllib2.Request("https://www.googleapis.com/oauth2/v3/token", data=urllib.urlencode(post_data), headers={'User-Agent': 'Mozilla/5.0'})
req.get_method = lambda: 'POST'
res = urllib2.urlopen(req)
if res.code == 200:
print "response 200 : "
else:
print "Access Token Validation Return Code: ", res.code
This web service call returns 200 and token when the auth-code is generated from Android. When it is sent from web, the same method throws the following error..
Error: 400, invalid request; missing parameter 'redirect_uri'
In this case, I don't need to send any redirect_uri, because I am reading the response there itself. But I still tried setting an empty value and also tried setting it to some value that exactly matches one of the values in google developers console. In that case, I am still getting..
Error: 400, invalid request; redirect_uri mismatch.
I cannot get my head around the fact that this web service call is working perfectly for android codes and not for web codes. Please note that scopes are different for Android app and Web app. But still, this seems to be some fundamental error. Any help would be appreciated.
I tried but there seems to be a problem in making a GET Request to a heroku URL example "https://xxxx-xxxxx.herokuapp.com/xxxxxx/xxxxxxxx"
I know the general method is
HttpClient client = factory.getHttpClient(); //or any method to get a client instance
Credentials credentials = new UsernamePasswordCredentials(username, password);
client.getState().setCredentials(AuthScope.ANY, credentials);
And I know that getState() is not available for 3.x version.
I don't know how the Chrome's "Advance REST Client" has handled it, it gave me the pop up and asked for the username and password and I entered Credentials and it worked and since then its working fine. I thought It might have stored the credential locally but, its not the case. I checked all the cookies and cache. I deleted the extension and cleared data and its still working.
Then I tried to use another REST Client by WizTools (for Mac). In the Authorization section there are 3 options. 1.) Basic, 2.) Digest and 3.)Preemptive, I did some permutation and combination with it using the given Credentials but all the time it gave the same response i.e.
"HTTP/1.1 406 Not Acceptable"
I don't understand what's the issues is?
Thanks,
I don't know, if why is it not working, but I used URLConnecton used the authentication mentioned and it worked. I got the response. And yeah BTW I had to assign the "Accept" type a s "Application/Json"
I am developing an Android application and need to get the "me" info from google but I always ends up in either response code 401 or 403. What am I doing wrong?
Here is my code:
private static final String GOOGLE_AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/plus.me";
I get the oauth token by (note...code below is shortened):
Account googleAccount = (AccountManager) getSystemService(ACCOUNT_SERVICE).getAccountsByType("com.google")[0];
final Bundle bundle = manager.getAuthToken(googleAccount, GOOGLE_AUTH_TOKEN_TYPE, true, null, null).getResult();
String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
So far so good... I now have a token so everything looks good here.
Now get the me info:
String GOOGLE_ME_URL = "https://www.googleapis.com/plus/v1/people/me";
final DefaultHttpClient client = new DefaultHttpClient();
final HttpGet request = new HttpGet(GOOGLE_ME_URL);
request.addHeader("Authorization", "OAuth=" + authToken);
final HttpResponse response = client.execute(request);
This gives response code 401.
I have also tried:
final DefaultHttpClient client = new DefaultHttpClient();
final HttpGet request = new HttpGet(GOOGLE_ME_URL + "?access_token=" + authToken);
final HttpResponse response = client.execute(request);
This gives response code 403 - Something like "Daily limit exceeded. Please sign up".
What am I doing wrong? what have I missed? How should this be done?
Thanks
// Edits below
Some more investigation:
I added a project into code.google.com/apis/console and took the key generated from there and put into the url, like:
https://www.googleapis.com/plus/v1/people/me?key=my_generated_key&access_token=" + authToken.
Now the call works fine and I get a 200 response with the correct info. But I really don´t want to use this method if I don´t have to and according to google I should not need to "•If the request requires authorization (such as a request for an individual's private data), then it must include an OAuth 2.0 token. It may also include the API key, but it doesn't have to." - from developers.google.com/+/api/oauth.
Another thing:
If I try another url like
"https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + authToken
it works fine.
The issue is regarding the simple api key passed into the request.
If the key parameter isn't included in the request, or if the Google+ API wasn't activated for that project, you'll get the error:
"Daily limit exceeded. Please sign up".
To solve this problem, you need to do the following:
Visit the Google API Console here: https://code.google.com/apis/console/?api=plus
Under the Services panel, make sure the Google+ API is turned "on".
In the APIs console, click API Access in the left menu.
Copy the API key presented towards the bottom.
Include this API key in your HTTP request.
GOOGLE_ME_URL + "?access_token=" + authToken + "&key=" + MY_SIMPLE_API_KEY
Most of the newer Google APIs have quotas (like daily usage limits) and some even have billing support (where you get billed per API call). These quotas and billing are calculated per developer's project, and not on a per-end-user basis, so Google needs to know which app to assign your API usage.
API clients using Google's OAuth 2.0 are typically required to register and get a client ID and client secret.
This client ID and client secret are returned by the Google APIs console: code.google.com/apis/console.
You then use these values in your application, and this identifies your app and allows Google to assign your API usage to your developer account/project.
In the AccountManger interface you're using, there is no client ID passed by your app, so Google can't identify which developer account/project's quota to deduct for usage. It also doesn't know that the API has been properly enabled (TOS accepted, etc) by you as a developer. That's why it's asking you to "please sign up" and saying the "Daily limit exceeded" (as the unregistered limit is zero requests for many APIs).
In this scenario, it is necessary for you to pass the "key" value as you did in order to access APIs with OAuth 2.0 tokens retrieved from the AccountManager.
Why don't some of you try to go to the Google Console. In this way you will be able to have access to to the tools you need to rectify at least 403 forbidden problems. DMC
Generate a new auth token and secret for your application and try again.
That might solve your problem, but your daily retry limit might be exhausted...
I had the same issue you're having.
You are using HTTP at the moment, but you are actually calling a the site over HTTPS. Either use a secure connection procedure or use the http:// address.
You just need to enable Google+ API in console.
this Android code worked fine before, but i'm having problems for some reason. here is the request i'm trying to make:
https://www.google.com/reader/api/0/token
i'm getting 400:Bad Request as a response, and i'm not sure why. isn't this the correct URL for requesting a token? the auth token is being passed as a header in all requests now, and i can request feed list, and it works just fine, so there's nothing wrong with the auth code. what gives?
in addition, i can request a token in a normal browser, like Chrome, and get a token as a response body. so the request itself is not the problem. i just can't figure out what is wrong with my requests in code...
the answer is to use http rather than https. if anyone else is having trouble getting tokens from the unofficial google reader api, check whether you are using secure http or not.