- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Angular 应用,我想在此 Angular 应用中添加 Gmail。
我已经遵循了本教程 https://medium.com/@mcflyDev/angular-2-or-4-import-google-contacts-d0ffb13d8626
一切正常,我收到了 access_token
的成功响应,但没有收到 authorization_code
。
如何获得authorization_code
?
这是我的配置:
this.auth2 = gapi.auth2.init({
client_id: 'bla-bla-bla-2.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
scope: 'https://www.googleapis.com/auth/gmail.readonly',
access_type: 'offline',
response_type: 'code',
auth_uri: 'https://accounts.google.com/o/oauth2/v2/auth',
prompt: 'select_account',
include_granted_scopes: true,
grant_type: 'authorization_code',
});
此外,我也没有获得 refresh_token
,正如您所看到的,我已经设置了 access_type: 'offline'
。
我收到的回复如上图所示。
谢谢。
最佳答案
我找到了解决方案。早些时候,我进行了 POST
Ajax 调用,但这不是必需的。
我们只需要分两步进行一个小设置:
第 1 步:准备 URL:
URL 应如下所示:
https://accounts.google.com/o/oauth2/auth?redirect_uri=:your_redirect_url&response_type=code&client_id=:your_client_id&scope=https://www.googleapis.com/auth/gmail.send&approval_prompt=force&access_type=offline
您可以将此 URL 粘贴到浏览器中,然后按 Enter 键检查其是否正常工作。
步骤 2. 在 HTML 中创建 anchor 标记:
<a href="giveAboveURLHere">Connect With Gmail</a>
恭喜!!!你已经完成了。
每当用户点击此链接时,Google 都会请求所提供范围的许可,如果最终用户授予访问权限,则 Google 将使用 重定向到给定的
。redirect_url
查询参数中的authorization_code
然后在服务器端,您需要使用此 authorization_code
进行另一个 API
调用,然后 Google 将提供 access_token
和 刷新 token
。
谢谢,希望对你有帮助。
关于javascript - 如何在Angular 5应用程序中从Gmail API获取authorization_code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51841868/
对于 Postman 中的许多集合,我们使用授权类型 =授权代码(到 Azure)。对于使用授权类型客户端凭据的请求,我可以编写自动获取 token 的预请求脚本(如果需要),并且我希望有一个用于授权
我的项目是 python 并使用 boto3 库。 我正在使用 aws cognito 授权代码授予流程和 return_type=code 而不是 return_type=token(隐式流程)。一
我正在使用 spring boot oauth2 尝试设置授权代码授予流程。授权端点工作,生成代码并将其存储在我们的 postgres 存储中。但是,使用代码获取 token 的第二步不起作用。 我没
我正在开发 API AI 代理,并尝试实现帐户链接功能。文档位于 oauth2-codeflow真的很有帮助,我能够创建我的 oauth 流程并在 Google playground 中进行测试。 .
我正在尝试使用身份服务器授权我的 angular 客户端。以下是我的 Angular 客户端的设置。 authority: 'http://localhost:5000', client_id
我有 3 个应用程序 前端应用 OAuth2 身份验证服务器 REST API(RepositoryRestResources) 我的用户必须先登录才能使用前端应用程序。这是通过 SSO 实现的。他们
代码片段为 帖子网址为 https://accounts.google.com/o/oauth2/token 范围是“https://www.googleapis.com/auth/userinfo.
据我了解,在授权代码流程中,我们需要获取授权代码并在之后使用它来获取 token 。只有当用户确认指定访问权限时,我们才能获得此代码。之后浏览器将我们重定向到 redirect_uri 并且响应将包含
我正在用 django 开发一个应用程序,当我尝试使用 auth0 登录时,我得到: "error": { "message": "Grant type 'authorization_code'
我正在尝试使用 authorization_code 授权流程设置身份验证。我之前曾使用过 grant_type=password ,所以我知道这些东西应该如何工作。但是当使用 grant_type=
我正在尝试创建一个简单的支持 OAuth 的概念验证应用程序,但卡在授权代码实现上。我读到的所有地方似乎都以这样或那样的方式进行,从未真正使用过授权代码流。我一直在使用以下资源获取信息: https:
我正处于 Authorization Code Grant Flow 之中使用 Azure AD。尽管文档说 grant_type 应该是 authorization_code,但我收到了有关此属性的
我是一名优秀的程序员,十分优秀!