我正在尝试遵循此 dart + google auth 入门(https://github.com/dart-lang/googleapis_auth),但我很难找到对 javascript sdk 工具包的类似调用(https://developers .google.com/api-client-library/javascript/samples/samples#authorizing-and-making-authorized-requests)
什么是等效的 isSignedIn,您如何访问请求的范围详细信息,例如用户个人资料/电子邮件信息?
我认为这可以通过调用 peoples api 来完成,但没有成功
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);
});
});
}
}
编辑:我确实想添加文档说:“经过身份验证的 HTTP 客户端现在可以代表用户访问请求的 oauth2 范围的数据”,但我看不出这是如何实现的。目标只是检查用户是否登录,并获取他们登录时使用的电子邮件地址。
编辑 2:我设法取得了一点基础,我相信,并在其中创建了一个新的 PeopleApi 客户端,但这会引发两个错误:
dart_sdk.js:15886 拒绝设置不安全的标头“user-agent” dart_sdk.js:15886 拒绝设置不安全的标头“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);
});