OAuth 2.0电子邮件地址

时间:2013-01-05 01:16:04

标签: coldfusion oauth

如果我执行以下操作:

<cflocation url="https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&client_id=#Application.Google.client_id#&redirect_uri=http%3A%2F%2Fwww.PhillipSenn.com%2FLR%2FGoogle%2FCallback&response_type=code" addtoken="no">

然后我正确地获得了“允许访问”和“不再感谢”屏幕。 然后我允许访问,并正确调用我的回调屏幕。

问:我现在该怎么办?我需要确定用户的电子邮件地址。

我唯一看到的是:url.code,它看起来不可用。 我必须打电话

https://www.googleapis.com/oauth2/v1/userinfo

使用称为access_token的东西?我不这么认为,因为那是在谈论JavaScript,而我正在做所有这些服务器端。此外,我不需要用户个人资料信息 - 我只需要他们的电子邮件地址。

编辑:

This link看起来很有希望。

3 个答案:

答案 0 :(得分:1)

该呼叫为您提供access_token,允许您(在有限的时间内)访问用户信息。无论你在哪里使用它,服务器端都可以。

请确保您向https://www.googleapis.com/oauth2/v1/userinfo的请求access_token=youraccess_token作为参数

答案 1 :(得分:0)

Google首次重定向时,您必须执行以下操作:

<form method="post" action="https://accounts.google.com/o/oauth2/token">
    <input name="code" value="#url.code#">
    <input name="client_id" value="#Google.client_id#">
    <input name="client_secret" value="#Google.client_secret#">
    <input name="redirect_uri" value="#Google.redirect_uri#">
    <input name="grant_type" value="authorization_code">
    <input type="submit" name="getAccessToken" value="Get Access Token">
</form>

答案 2 :(得分:0)

您必须执行以下操作:

<cfhttp method="post" name="qry" url="https://accounts.google.com/o/oauth2/token">
    <cfhttpparam type="formfield" name="code" value="#url.code#">
    <cfhttpparam type="formfield" name="client_id" value="#Google.client_id#">
    <cfhttpparam type="formfield" name="client_secret" value="#Google.client_secret#">
    <cfhttpparam type="formfield" name="redirect_uri" value="#Google.redirect_uri#">
    <cfhttpparam type="formfield" name="grant_type" value="authorization_code">
</cfhttp>
<cfdump var="#qry#">