带有Grails访问令牌的oauth facebook [英] oauth facebook with grails accessing token

查看:108
本文介绍了带有Grails访问令牌的oauth facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个grails项目,
通过oauth,Facebook身份验证成功,
现在,当返回到我的控制器时,我想获取登录用户的电子邮件ID,
搜索了很多,但没有找到合适的文档,
我正在使用scribe,并且在Config.groory中有以下代码

Its a grails project,
Facebook authentication is successful via oauth,
Now when it comes back to my controller, I want to get emailID of the logged in user,
Searched a lot, but did not find proper documentation,
I am using scribe and have following code in Config.groory

import org.scribe.builder.api.FacebookApi

oauth {
providers {
    facebook {
        api = FacebookApi
        key = 'xxxx'
        secret = 'yyyy'
        callback = "http://my-domain-name-here:8080/TestOAuth2/dashBoard/facebooklogin"
        successUri = "http://my-domain-name-here:8080/TestOAuth2/dashBoard/success"
    }
}
}

任何帮助,不胜感激.
谢谢.

Any help much appreciated.
Thanks.

推荐答案

尝试一下..,.

配置:

import org.scribe.builder.api.FacebookApi
...
oauth {
  providers {
    facebook {
      api = FacebookApi

      key = 'XXX'
      secret = 'YYY'

      scope = 'email,read_stream,publish_actions,user_birthday,publish_stream'

      callback = "http://localhost:8080/appName/oauth/facebook/callback"   //callback to oauth controller of oauth plugin

      successUri = "http://localhost:8080/appName/myController/facebookSuccess"
      failureUri = "http://localhost:8080/appName/myController/facebookFailure"
    }
  }
}

MyController:

def facebookSuccess() {
    Token facebookAccessToken = (Token) session[oauthService.findSessionKeyForAccessToken('facebook')]
    def facebookResource = oauthService.getFacebookResource(facebookAccessToken, "https://graph.facebook.com/me")
    def facebookResponse = JSON.parse(facebookResource?.getBody())

    log.info "Email = ${facebookResponse.email}"
    ...
}

您可以从我的git repo中获得工作示例. Grails Oauth插件演示.

You can get working example from my git repo. Grails Oauth Plugin Demo.

这篇关于带有Grails访问令牌的oauth facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆