davidesp
davidesp

Reputation: 3972

How to get user info with nativescript-oauth2 after user grants permission?

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!

Upvotes: 0

Views: 590

Answers (0)

Related Questions