我正尝试在Torii中使用github-oauth2提供程序,但是我很难理解如何设置一些回调。我会跟踪我使用的代码,以及我对它的理解,并希望能够帮助我确定哪里出错。通过Ember.js和Torii连接到github(oauth2)
首先,在我的行动,我打电话牌坊的open
方法,因为它说,在文档中要做到:
this.get('torii').open('github-oauth2').then((data) => {
this.transitionTo('dashboard')
})
,当然,我有我的config/environment.js
以下设置:
var ENV = {
torii: {
// a 'session' property will be injected on routes and controllers
sessionServiceName: 'session',
providers: {
'github-oauth2': {
apiKey: 'my key',
redirectUri: 'http://127.0.0.1:3000/github_auth'
}
}
},
}
redirectUri适用于我的Rails服务器。我有我的github应用程序相同的redirectUri设置,所以他们匹配。
这是我在我的服务器上。这可能是问题所在。我会在最后解决症状。
def github
client_id = 'my id'
client_secret = 'my secret'
code = params[:code]
@result = HTTParty.post("https://github.com/login/oauth/access_token?client_id=#{client_id}&client_secret=#{client_secret}&code=#{code}")
@access_token = @result.parsed_response.split('&')[0].split('=')[1]
render json: {access_token: @access_token}
end
所以我发布到GitHub的端点的access_token,因为我应该和我回去与访问令牌的结果。然后,我将该访问令牌打包为json。
这样做的结果是,牌坊弹出去铁轨页:
不幸的是,我希望的是为牌坊弹出消失,给我的应用程序的access_token
,和代码移动并执行我的then
块中的代码。
我哪里错了?