Omniauth - 在重定向网址中设置自定义参数

发布于 2024-12-21 16:10:53 字数 571 浏览 0 评论 0原文

我正在使用最新(1.0.1)版本的 Omniauth 和 Rails 3.1.3。 现在,我正在使用 37signals 策略的omniauth。我想根据 auth url 传递自定义参数(“state”参数)(例如 http://localhost: 3000/auth/37signals/5 应重定向到 https://launchpad.37signals.com/authorization/new?(...)&state=5

我尝试设置(暂时)固定状态,类似于

provider "37signals", "my_client_id", "my_secret", {state: "5"}

但是,在我的网址中(仍然)没有状态参数。 有什么想法吗?可以设置该参数吗?

I'm using latest (1.0.1) version of Omniauth with rails 3.1.3.
Right now, I'm using omniauth with 37signals strategy. I would like to pass custom argument ("state" parameter) depending on auth url (eg. http://localhost:3000/auth/37signals/5 should redirect to https://launchpad.37signals.com/authorization/new?(...)&state=5

I've tried to set (temporarily) fixed state, with something like

provider "37signals", "my_client_id", "my_secret", {state: "5"}

However, in my url there is (still) no state param.
Any ideas why? Is it possible to set that param?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七度光 2024-12-28 16:10:54

创建 url 时,您只需在查询字符串中添加状态,它也将在回调 url 中可用。

user_omniauth_authorize_path(:facebook, :display => 'page', :state=>'123') %>

现在回调 url 将是

http://localhost:3000/consumers/auth/facebook/callback?state=123&code=ReallyLongCode#_=_

现在在回调处理程序中您可以处理状态

when creating the url you can just add state in the Query String and it will be available in the callback url as well.

user_omniauth_authorize_path(:facebook, :display => 'page', :state=>'123') %>

now the callback url will be

http://localhost:3000/consumers/auth/facebook/callback?state=123&code=ReallyLongCode#_=_

Now in the callback handler you can process the state

长途伴 2024-12-28 16:10:54

您必须使用 :params 选项,因为在

omniauth_authorize_path(:user, :facebook, var: 'value', var2: 'value2' )

回调中以及稍后您可以访问 request.env['omniauth.params'] 来获取哈希值! :)

(复制自此答案

You have to use the :params options, as in

omniauth_authorize_path(:user, :facebook, var: 'value', var2: 'value2' )

and later in the callback you can access request.env['omniauth.params'] to get the hash! :)

(copied from this answer)

南烟 2024-12-28 16:10:54

我认为你不能为网址附加其他参数。服务器端就像指定参数一样。

也许你需要看看这个。

https://raw.github.com/tallgreentree/omniauth-37signals/e94a70a08c4535abb91338d8ef73593e143f1e5a/lib/omniauth/strategies/37signals.rb

I think you can not to appending other params for the url. the server side just like the specify params.

maybe you need to take a look this one.

https://raw.github.com/tallgreentree/omniauth-37signals/e94a70a08c4535abb91338d8ef73593e143f1e5a/lib/omniauth/strategies/37signals.rb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文