-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to do sign in through Google Authentication rather than through the API? #26
Comments
Yes. Please read the README before posting an issue |
Sorry, I was unclear with what I meant. I meant is it possible to do authentication with Google rather than the API.
The purpose of this is to allow for a more secure login rather than inputting your username and password into the API. |
Yes, this should be possible to do as long as the token returned by Google works for Niantec (I have no idea about which scope it needs, but I assume it'll just be viewing their e-mail address). Here's some reference documentation: https://developers.google.com/api-client-library/ruby/auth/installed-app I won't really get time before weekend to get this done, however, the only caveat is that machines that do not have a browser may not be able to authorize (in which case perhaps a URl can be given to visit and token can be be entered/set). We can also save the refresh token somewhere local (a file for example, Google's API client gem handles this) and keep using the refresh token to generate a new access token upon expiry. |
I'd say since this is just an API wrapper (with some extras), you can leave that implementation to the client that's integrating this gem. That should be a basic oauth flow and you can even use omniauth-google-oauth2 (i.e). I wouldn't consider that as a basic necessity for this gem and even more, I would consider it an overhead. |
I did try to implement it within my application with omniauth-google-oauth2 and ran into some problems. The steps I took were:
The error comes when I try to fetch_endpoint: Let me know if I missed anything. @elfenars |
@dphuang2 I read something about Niantic implementing cert-pinning on the endpoints now, I don't know if this applies to all the endpoints, but this sounds like either the endpoint changed or you're getting rejected. Have you tried the vanilla solution for this API and see if it works anyway? |
Or maybe everything was good and the endpoint just failed... try again :( |
Cert pinning its only enabled client side currently. Should not be an issue. |
Isn't |
Yeah it is, I am working on a web app. |
Ah I see, should the api client only expose a way to store the access token by Google then to use? As you said it doesn't feel right to implement the entire OAuth flow. Provided the access token works (unsure at the moment). |
I ran some tests and comparisons. I found that the @access_token of the GOOGLE Object from the client (from client.login) differs from the token I get from omniauth-google-oauth2. I assume that this is because omniauth uses Web login and poke-api implements the use of gpsoauth which is an Android login. The two tokens I get back from omniauth look like this (I tried using both and both gave: "Unable to fetch endpoint, please try to login again."):
The access_token from GOOGLE Object looks like this (looks similar to the id_token from omniauth):
The point of comparing the two were to see if similar token lengths meant they were both compatible (that is why I tried using the id_token). This is the line error is raised on:
It looks like using omniauth yields nothing when fetching an endpoint. Do any of you have an idea why the omniauth tokens do not work? |
Tokens that start with eY are JSON Web tokens, you should try and not share them (or garble them slightly) as they can share personal information (and are valid as well until expiry). I've edited your post so it's not valid a token anymore. I believe the first token you get back is an I'll look into it this weekend, in the meantime without having to worry about the entire OAuth flow you could get your access token from https://developers.google.com/oauthplayground/ (use scope profile) edit |
I garbled them slightly beforehand but thanks for the precaution :) Could I use gpsoauth myself to retrieve an access token with the first token? |
JSON Web tokens continue to show information even after slightly garbling them (unless you change quite a lot). Regarding GPSOAuth, I'm not sure, Android has a completely different way of authenticating with Google. I suppose you could compare the two tokens on https://jwt.io and see what their payload looks like? |
I see, thanks for the heads up. I'll try that out. |
I had a quick go at this as well, here's what I got Android {
"iss": "accounts.google.com",
"aud": "848232511240-7so421jotr2609rmqakceuu1luuq0ptb.apps.googleusercontent.com",
"sub": "117355651878090214803",
"email_verified": true,
"azp": "848232511240-3vdrtrfdntljf2u4mlgtnnlhnign35d5.apps.googleusercontent.com",
"email": "snip@gmail.com",
"iat": 1470254166,
"exp": 1470257766,
"name": "snip",
"picture": "snip",
"given_name": "snip",
"family_name": "snip",
} Google OAuth {
"iss": "https://accounts.google.com",
"at_hash": "8cmdAEc-4lYeIGueFL14MQ",
"aud": "407408718192.apps.googleusercontent.com",
"sub": "117355651878090214803",
"email_verified": true,
"azp": "407408718192.apps.googleusercontent.com",
"email": "snip@gmail.com",
"iat": 1470254218,
"exp": 1470257818,
"name": "snip",
"picture": "snip",
"given_name": "snip",
"family_name": "snip",
"locale": "en-GB"
} Perhaps the audience/authorized presenter needs to match? Not sure how Niantec are validating. I can't even test anything as every time I login in I get a blank api_url... (for both Google and PTC). |
I got similar results with my payload... On a side note, how is www.pokeadvisor.com doing google authentication? It redirects me to a get a token that is authorized by Niantic themselves: image |
I would guess that Niantec set their OAuth2 flow to local app instead of web app so anyone could use their address. This gives you a token back which probably then works when fed in to retrieve an access token. |
It's kind of clunky but I am guessing this is the only way to get a token through the web that validates with Niantic. |
Alright figured it out, this is what you have to do:
A bit of information, the client_id and client_secret are available on any Pokemon GO installation to be retrieved so that's where they come from (I just googled them up) As for urn:ietf:wg:oauth:2.0:oob (copy paste from Google)
|
Wow, nice job on the procedure. That would have taken me a while... I'll take a stab at it right now. |
Works like a charm! Here is the procedure I used:
I was wondering though, is there any way to do this without having to get the code manually? |
It is possible but it's going to be really hard to explain how, you basically have to 'spoof' being an actual user logging in while saving cookies and all that. HTTPClient can do all of this for you, but it'll be a lot of trial and error. Google Chrome's developer console (network tab) should be a great deal of help here too. I found this https://github.com/ernilos/PokemonGoApi/blob/4adfa7a891940156193aa6997ceb9fcd895a2f65/PokemonGoApi/AuthenticationService.cs which will hopefully explain the process. |
Thats a pretty hacky solution X_X. Well now that I know that it is possible I am going to close this issue. |
It might just be easier requesting the user to provide you the token, saves a lot of trouble and you get a re-usable refresh token you can store somewhere in your DB for that user to generate the access token indefinitely. |
In case anyone is interested, this https://github.com/kddeisz/poke-go-ivs encapsulates the google login business and shows you the IVs locally. |
👍 |
Edit for Clarification:
The purpose of this is to allow for a more secure login rather than inputting your username and password into the API.
The text was updated successfully, but these errors were encountered: