1

I'm trying to follow this dart + google auth getting started ( https://github.com/dart-lang/googleapis_auth ) but I'm having a difficult time finding similar calls to the javascript sdk kit ( https://developers.google.com/api-client-library/javascript/samples/samples#authorizing-and-making-authorized-requests )

What is the equivalent isSignedIn, and how do you access the scope details requested, like user profile / email information?

I thought this might be done by calling to the peoples api but am not successful

import 'package:angular/angular.dart';

import 'package:googleapis_auth/auth_browser.dart' as authBrowser;
import 'package:googleapis_auth/auth.dart' as auth;
import 'dart:developer';

@Injectable()
class AuthService {

  static final _clientId = "hidden-.apps.googleusercontent.com";
  static final _secret = "";
  final List<String> _googleScopes = ["email","profile", "openid"];

  static final _identifier = new authBrowser.ClientId(_clientId, _secret);

   signIn(event)  {
     return authBrowser
     .createImplicitBrowserFlow(_identifier, _googleScopes)
     .then((authBrowser.BrowserOAuth2Flow flow) {
        debugger();
       flow
          .clientViaUserConsent()
          .then((auth.AutoRefreshingAuthClient client) {

              final _test = await client.get(
              'https://people.googleapis.com/v1/people/me', 
            ); //returns 403 error, and subsequent no authorization header present

            print(client);
        });
     });
   }
}

Edit: I did want to add the documentation says: "The authenticated HTTP client can now access data on behalf a user for the requested oauth2 scopes", but I cant see how this is achieved. Goal is just check if a user is signed in, and grab their email address they signed in with.

Edit 2: I managed to make a little ground I believe, and pulled in this to create a new PeopleApi client, but then this kicks out two errors:

dart_sdk.js:15886 Refused to set unsafe header "user-agent" dart_sdk.js:15886 Refused to set unsafe header "content-length"

flow
      .clientViaUserConsent()
.then((auth.AuthClient client) async {

        debugger();

        await new PeopleApi(client).people
        .get('people/me', personFields: 'coverPhotos,emailAddresses')
        .then( (Person person) {
          print(person);
        });
mgoya
  • 512
  • 3
  • 12
james
  • 408
  • 7
  • 22

0 Answers0