从 Google 登录和 Google 课堂迁移

Migrating from Google Sign-In and Google Classroom

我目前正在尝试向我们的教育网站添加 google 登录支持。大多数时间用户只会使用 Google 登录,但偶尔教师也需要能够从 Google 课堂导入学生花名册。我已经使用来自 Classroom 开发者网站的指南(https://developers.google.com/classroom/quickstart/js). I'm using https://apis.google.com/js/api.js 让用户登录(gapi.auth2.getAuthInstance().signIn),仅使用“配置文件”范围,然后授予额外的教室范围,如果教师需要的话。

我正在阅读迁移到 Google 登录指南(https://developers.google.com/identity/gsi/web/guides/migration) and trying to work out if it applies to us or not. It's explicitly saying not to use gapi.auth2/gapi.client etc anymore and to use the new Identity Services Library instead, but there's no explanation how to use that to make API calls to Classroom (or any other Google API). The OAuth 2.0 JS guide (https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow)仍然说要使用 gapi.auth2 等。

所以我应该使用新库来让用户登录,而不是 api.js?

如果是这样,我是否仍应该使用 gapi.auth2 进行 API 调用,还是应该以某种方式使用新库?

登录认证和数据访问授权正在分离。使用新的身份服务库进行登录,而不是 api.js 和配置文件范围。根据您分享的内容,大多数用户应该属于这种情况。

稍后,根据需要,继续使用 gapi.auth2 获取访问令牌并调用课堂或其他 Google API。

从功能上讲,这看起来像是使用 HTML 或 JavaScript 从 gapi.auth2 和 access/refresh 令牌中分离出您的登录流程。调用 API 的令牌请求(使用隐式或授权代码)将仅在需要时发出。假设您将在某个时候使用 3 个不同的范围,仅在必要时才会请求每个范围,也称为 incremental authorization.