我正在尝试遵循此dart +谷歌身份验证入门(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是什么,如何访问请求的范围详细信息,例如用户个人资料/电子邮件信息?
我认为可以通过调用人民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拒绝设置不安全的标头“用户代理” dart_sdk.js:15886拒绝设置不安全的标头“内容长度”
flow
.clientViaUserConsent()
.then((auth.AuthClient client) async {
debugger();
await new PeopleApi(client).people
.get('people/me', personFields: 'coverPhotos,emailAddresses')
.then( (Person person) {
print(person);
});