Skip to content
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

How to obtain a user ID and OAuth access token in Dialogflow #11

Open
ghost opened this issue Feb 27, 2019 · 8 comments
Open

How to obtain a user ID and OAuth access token in Dialogflow #11

ghost opened this issue Feb 27, 2019 · 8 comments
Assignees

Comments

@ghost
Copy link

ghost commented Feb 27, 2019

While I posted a comment on it here I still think there's an issue here as described in https://stackoverflow.com/questions/54871395/how-to-obtain-a-user-id-and-oauth-access-token-in-dialogflow.

Why should I be doing some coding acrobatics to get to accessToken, for example:

String accessToken = ((DialogflowRequest)request).getAogRequest().getUser().getAccessToken();

while the more straightforward methods advertised via the API don't work (always returning null):

String idToken = request.getUser().getIdToken();
		log.info("request.getUser().getIdToken()={}",idToken);

Ditto for other fields, i.e. userId, sessionId, isSigninGranted, etc.

Or, am I missing something?

@Fleker
Copy link
Member

Fleker commented Feb 28, 2019

Just to confirm, the first snippet does work as expected?

@ghost
Copy link
Author

ghost commented Feb 28, 2019

Yes, this works:

String accessToken = ((DialogflowRequest)request).getAogRequest().getUser().getAccessToken();
but as it's been discovered via some deep debugging sessions and not really advertised anywhere, I'm cautious about using it as it may break in the future in case of impl change.

And this doesn't work: request.getUser().getIdToken()=null

Should it not return consistent results?

@aradwyr
Copy link

aradwyr commented Mar 29, 2019

Check out the Google Sign In sample in Java but specifically here:

  private boolean userIsSignedIn(ActionRequest request) {
    String idToken = request.getUser().getIdToken();
    LOGGER.info(String.format("Id token: %s", idToken));
    if (idToken == null || idToken.isEmpty()) {
      return false;
    } else {
      return true;
    }
  }

I'm closing this out but if you're still facing issues let us know.

@aradwyr aradwyr closed this as completed Mar 29, 2019
@ghost
Copy link
Author

ghost commented Mar 29, 2019

@sarahdwyer I saw that, but it doesn't address the issue I'm experiencing

@taycaldwell
Copy link
Contributor

Did you set up Account Linking for your project? If so, what configuration did you choose (Google Sign-In, OAuth, etc.)?

@ghost
Copy link
Author

ghost commented Apr 7, 2019

We did via OAuth's Authorization code flow

@morphine9
Copy link

@slkasisto if you added OAuth, then user info needs to come from your authentication/authorization provider. The access token you get back from request.getUser().getAccessToken() is the access token to your oauth provider

@ghost
Copy link
Author

ghost commented May 29, 2019

That is understood, however it was not populating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants