Ege*_*soz 10 google-calendar-api elixir oauth-2.0 google-oauth
我的应用会在用户的Google日历上发布,修改和删除活动.我正在配置OAuth以实现这一目标.这个想法是,在注册后,用户将能够进入他们的设置并同意将我的应用程序连接到他们的Google日历.然后,我将能够在数据库中存储oauth令牌和刷新令牌,并在用户日历上创建/编辑/删除事件时使用它们.
无论如何,问题是我选择了我的帐户:
然后我点击"允许"提供同意:
以下是它变得奇怪的地方:在幕后,Google Calendar API会报告403 Forbidden错误.
%Ueberauth.Failure{errors: [%Ueberauth.Failure.Error{message: 403,
message_key: "OAuth2"}], provider: :google,
strategy: Ueberauth.Strategy.Google}
Run Code Online (Sandbox Code Playgroud)
我的ueberauth配置:
config :ueberauth, Ueberauth,
providers: [
google: {Ueberauth.Strategy.Google, [default_scope: "https://www.googleapis.com/auth/calendar", approval_prompt: "force", access_type: "offline"]}
]
Run Code Online (Sandbox Code Playgroud)
我正在提出的要求:
def callback(%{assigns: %{ueberauth_failure: fail}} = conn, _params) do
IO.inspect fail
conn
|> put_flash(:error, "Failed to authenticate.")
|> redirect(to: "/")
end
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
IO.inspect auth
conn
|> put_flash(:success, "Connected to Google.")
|> redirect(to: "/")
end
Run Code Online (Sandbox Code Playgroud)
第一个callback函数是匹配的函数(因为它失败).
但是,当我转到我的Google帐户时,我可以看到该应用已被授予权限:
我提供了正确的client_id和client_secret.此外,我在Google API控制台中创建了一个服务帐户,并与该帐户共享了我的日历:
我还需要做什么?
编辑:更多信息 - 我可以通过我的代码(浏览器Ueberauth_Google)授予访问所有其他Google模块的权限.例如,如果我使用电子邮件作为范围发出请求,它就可以工作,我从Google获得auth_token.只有谷歌日历提供403,这使我相信有一些特定的东西导致它.
编辑2:我查看了Google Calendar API的错误处理部分,其中列出的403错误都不适用于我:
编辑3:我创建了一个全新的Google帐户,并与我的Google服务帐户共享其日历.但是那个给出了同样的错误.
终于想通了.
在https://www.googleapis.com/auth/calendar自身范围是不够的.还需要添加https://www.googleapis.com/auth/userinfo.profile到范围.
| 归档时间: |
|
| 查看次数: |
523 次 |
| 最近记录: |