【发布时间】:2018-05-15 06:27:24
【问题描述】:
我是一个正在实践谷歌oauth2.0的人。我正在创建一个示例,但它不适用于 Oauth 身份验证。
首先,index.html中的操作如下。使用 href 命令请求带有简单标记的 Oauth“请求令牌”。
<a href="https://accounts.google.com/o/oauth2/v2/auth?
scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.readonly&access_type=offline&
include_granted_scopes=true&state=state_parameter_passthrough_value&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2FreceiveCode&response_type=code&client_id=665922514832-f7n0s3chgn41vsojtg4gfl2j7c5a5lfr.apps.googleusercontent.com">Using google API
</a>
<form action='http://localhost:3000/user' method='get'>
<button name="subject" type="submit" value='THIS 123!@# IS GET!!' href='www.google.com'>get</button>
</form>
这里授权的重定向URI是http://localhost:3000/receiveCode。
我想使用 restful API 而不是使用 php 文件。
到目前为止,它运行良好。问题是登录 Google 网站后我无法使用 Scope。 根据谷歌参考https://developers.google.com/identity/protocols/OAuth2WebServer的第5步,
一个会话被链接到一个授权的重定向URI,然后各种数据如Code值被发送到POST请求一个Access Token
但是,在我设置为路由器的receiveCode中,它始终是GET。
代码如下所示,结果 URL:
router.get('/receiveCode', (req, res, next) => {
//NOT ERROR BUT NOT POST
})
router.post('/receiveCode', (req, res, next) => {
// ERROR (Internal Server Error)
// actually... never calling enter post method
})
我不确定这是结构问题还是使用 post 的 API。
你不应该首先在 express 中使用 restAPI 吗?
【问题讨论】: