I received email from facebook that my rails app is using v2.0 api and it will be deprecated. so I updated gem like this.
- devise (3.5.6)
+ devise (4.2.0)
- oauth2 (1.1.0)
+ oauth2 (1.2.0)
omniauth-facebook (3.0.0)
omniauth-oauth2 (1.3.1)
I did not version up omniauth-oauth2 because of some unsolved issues.
after that, I change some deprecated view codes. and changed my config and restart server.
config.omniauth :facebook, APP_ID, APP_SECRET, scope: 'email', info_fields: 'email,name'
It worked well but the facebook api version was still v2.0. so I googled and found this. https://github.com/mkdynamic/omniauth-facebook#api-version says that it's default version is v2.6 but I don't know why it still use v2.0. anyway, I changed config code like this.
config.omniauth :facebook, APP_ID, APP_SECRET, scope: 'email', info_fields: 'email,name', client_options: {
site: 'https://graph.facebook.com/v2.6',
authorize_url: "https://www.facebook.com/v2.6/dialog/oauth"
}
but it did not work. log is like this.
Started GET "/users/auth/facebook/callback?code=verylogcode&state=stateblabla" for 127.0.0.1 at 2016-07-26 22:52:03 +0900
(facebook) Callback phase initiated.
(facebook) Authentication failure! invalid_credentials: OAuth2::Error, :
{"access_token":"very_long_token_value","token_type":"bearer","expires_in":5160039}
Processing by OmniauthCallbacksController#failure as HTML
I downgraded the config version to v2.3 but it did not work. from v2.2, it works.
My Question is this.
I found the answer here. https://github.com/mkdynamic/omniauth-facebook/issues/204
I saw this post before but I overlooked it.
solution is to add token_params: { parse: :json }
to config like this.
config.omniauth :facebook, APP_ID, APP_SECRET, scope: 'email', info_fields: 'email,name', client_options: {
site: 'https://graph.facebook.com/v2.6',
authorize_url: "https://www.facebook.com/v2.6/dialog/oauth"
}, token_params: { parse: :json }