0

I'm working on a basic Nativescript app based on the demo on:

https://github.com/alexziskind1/nativescript-oauth2/blob/master/demo-angular/src/app/auth.service.ts

import { Injectable } from "@angular/core";

import {
  TnsOAuthClient,
  ITnsOAuthTokenResult
} from "nativescript-oauth2";

@Injectable()
export class AuthService {
  private client: TnsOAuthClient = null;

  constructor() { }

  public tnsOauthLogin(providerType): Promise<ITnsOAuthTokenResult> {
    this.client = new TnsOAuthClient(providerType);

    return new Promise<ITnsOAuthTokenResult>((resolve, reject) => {
      this.client.loginWithCompletion(
        (tokenResult: ITnsOAuthTokenResult, error) => {
          if (error) {
            console.error("back to main page with error: ");
            console.error(error);
            reject(error);
          } else {
            console.log("back to main page with access token: ");
            console.log(tokenResult);
            resolve(tokenResult);
          }
        }
      );
    });
  }

  public tnsOauthLogout() {
    if (this.client) {
      this.client.logout();
    }
  }
}

Which gets back the access token.

My question is, how can I get the user info with that library: nativescript-oauth2?

I know that when you have the access token you can get some user info (id, name, email, etc.). For example, with Facebook you can do it in the following way by using the (dummy) access token:

https://graph.facebook.com/me?access_token=EAAF9wRREKB4BANZAZCNzp0nhmY8dgttSicR3u3aOxieEYR0kZAw298lHZAsgIwAeA9n4MeBWKivZBZB0ElFbzvo5N49kpIVozNKWFslcYIssdORsg4hHelxJI05ZBuycBjm6VrDpwWlljXkNCLR8prtdopt4mBWMYbqNouzpfn9JrF6TyXCaa2D4DhZBD4pOCBwZD

Is there any way to get the user info (id, name, email, etc.) with that library nativescript-oauth2?

How do I specify the scope of the fields I want to retrieve?, for example: { name, email, etc } by using nativescript-oauth2?

Thanks!

davidesp
  • 3,743
  • 10
  • 39
  • 77
  • The [example](https://github.com/alexziskind1/nativescript-oauth2/blob/master/demo-custom-provider/app/auth-service.ts#L24) already seems to demonstrate how you should pass scopes, did you try that? – Manoj Jun 24 '19 at 13:19
  • @Manoj, that's the way you can ask for the scope, but I mean, how do you get the actual values for email, name, id, etc? – davidesp Jun 25 '19 at 02:01
  • 1
    I don't think that's the job for the plugin, it's all about only authenticating the user with the token. For further information, you might have to use the respective SDKs / APIs of the service you are using. – Manoj Jun 25 '19 at 06:38
  • Anything you found out @david – Prajil Shrestha May 20 '20 at 09:10

0 Answers0