1

I have the following code, which I am using successfully in another program

index.html Eat Fresh

</html>

init.js

function init() {
    CLIENT_ID = "927885761089.apps.googleusercontent.com"
    SCOPES = ["https://www.googleapis.com/auth/userinfo.email"]
    gapi.client.load('oauth2', 'v2', signin)
}

function signin() {
    gapi.auth.authorize({client_id: CLIENT_ID, scope: SCOPES, immediate: true}, userAuthed)
}

function userAuthed() {
    console.log(gapi.auth.getToken())
    console.log(gapi.auth.getToken().accessToken)
    gapi.client.oauth2.userinfo.get().execute(function(resp) {
    checkEmail(resp)
    })
}

function checkEmail(user) {
    var validEmail = (whiteList.indexOf(user.email) !== -1)
    if (!user.code && validEmail) {
        startApp()
    } else {
        displayError(user.email)
    }
}

gapi.auth.getToken() is returning null and to my knowledge that means that my I am not logged in. I don't know how to refresh the login or force a log out. Any help would be appreciated.

Phedg1
  • 1,888
  • 3
  • 18
  • 35
  • 2
    Hi, You talk about Google app engine but I can see only js code. So to get an email address via oauth2 you can see this link http://stackoverflow.com/questions/11606101/how-to-get-user-email-from-google-plus-oauth and you can also test the API in the oauth2 play ground https://developers.google.com/oauthplayground/ – olituks May 14 '14 at 13:51
  • After some playing I've found that I was never prompted to allow this app to view my profile. I tested this theory by revoking the privileges for a similar app and it showed the same result in debugging. However, I don't know how to reprompt the user for this and now have 2 broken apps. – Phedg1 May 14 '14 at 20:41

1 Answers1

1

Changing the the following

gapi.auth.authorize({client_id: CLIENT_ID, scope: SCOPES, immediate: false}, userAuthed)

will prompt the user to give permission to the app, thus allowing for an authorized access token and for the remainder of the code to work.

Phedg1
  • 1,888
  • 3
  • 18
  • 35