Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My 2c is avoid oauth2 libraries. Of course opinions may vary, but for me they provide very leaky abstractions, so you end up being dragged into understanding oauth by the back door. For me at least, taking an hour to read the the two pages that tell you all you need to know, and carefully avoiding all the others, will get you where you want to be.</p> <p>In simple terms, the steps are :-</p> <ol> <li><p>Call the auth URL with your app/client ID and the scopes you require. Include the "email" scope.</p></li> <li><p>Google will walk the user through login, and (if the first time through) authorisation dialogues</p></li> <li>Eventually the browser will redirect back to your oauthcallback url, and pass you an auth code</li> <li>Call google to convert the auth code to a refresh token. This will also return the user's google ID and an access token.</li> <li>Store the user ID in your session so you can identify the user subsequently</li> <li>Persist the refresh token alongside the google user id in a database</li> </ol> <p>On subsequent visits...</p> <ol> <li>If you have the google user id in the your session, you can retrieve the refresh token from your database and use it to generate access tokens as you need them.</li> <li>If you do NOT have the google user id in your session, go through the steps above. This time, google will NOT prompt the user for authorisation (since it's already authorised), and the refresh token will be blank (since you already have one stored).</li> </ol> <p>Everything you need to know is within the oauth playground page. If you click through the buttons, you will see that it is following the steps I outlined above. </p> <p>You then need to deal with the possible error situations, eg</p> <ul> <li>user declines permission</li> <li>user withdraws permission</li> <li>google expired the refresh token (happens a lot) so you need to re-auth</li> <li>timeouts </li> </ul> <p>The two pages you need to read are :- <a href="https://developers.google.com/accounts/docs/OAuth2WebServer" rel="noreferrer">https://developers.google.com/accounts/docs/OAuth2WebServer</a> and the oauth playground at <a href="https://developers.google.com/oauthplayground/" rel="noreferrer">https://developers.google.com/oauthplayground/</a></p> <p>Trust me, as long as you know how to form a URL, store a refresh token (it's just a string) and parse a JSON response, then everything you need is on those pages. Except ...</p> <p>all the documentation skips over the need to preserve the user ID in your session so you know who it is that is accessing your app. If you're on AppEngine, you may be confused by the appengine sample code which uses a separate appengine login. Ignore it. You will be using oauth to authenticate the user so the appengine stuff doesn't apply and is somewhat confusing. </p> <p>It's actually much simpler than some of the documentation would lead you to believe, and like I said, imho the leaky libraries don't help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload