stranbird

Rails里面如果要做一个Oauth过程,在求Authorize的时候会redirect。该怎么维护那个consumer对象?把token和secret存在session里面?

  •  
  •   stranbird · Apr 1, 2011 · 6540 views
    This topic created in 5527 days ago, the information mentioned may be changed or developed.
    5 replies    1970-01-01 08:00:00 +08:00
    icyflash
        1
    icyflash  
       Apr 1, 2011
    dreamer
        2
    dreamer  
       Apr 1, 2011
    真巧,我最近也在研究这个。

    你也可以不存到 session 里,在 Authorize redirect 的时候可以带上 oauth_callback 参数,把 token 和 secret 带上就行了,例如:

    http://xxx.com/authorize?oauth_token=xxxx&oauth_token_secret=xxx&oauth_callback=http://yourname.com/aaa?oauth_token=xxx&oauth_token_secret=xxx

    等授权通过之后,对方会跳转到 oauth_call_back 指定的网址,这样你就可以获取 http query string 了。
    chloerei
        3
    chloerei  
       Apr 1, 2011
    做过一次,觉得未校验成功时放session里面比较环保。校验成功了再存数据库里。

    另外可以看看这个 https://github.com/intridea/omniauth
    stranbird
        4
    stranbird  
    OP
       Apr 1, 2011
    @dreamer 好办法
    stranbird
        5
    stranbird  
    OP
       Apr 1, 2011
    还有个问题,是不是认证的方法一定要放在controller里面?
    但是每次都在controller里边放一个OAuth::Consumer.new感觉很奇怪。
    model里边可以放么?好像model里边没有redirect_to啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5086 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 03:53 · PVG 11:53 · LAX 20:53 · JFK 23:53
    ♥ Do have faith in what you're doing.