我正嘗試在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
塊中的代碼。
我哪裏錯了?