2016-12-15 5 views
2

私はInstagram Omniauthとの統合を数年間行っていますが、何も変えていませんが、Instagramアカウントを接続するときに顧客が時折青色からエラーを出すことがあります:Instagram Omniauth on Rails invalid_credentials

Started GET "/auth/instagram/callback?code=d3b1c4d88e2f440b8a8a98037b821c15&state=2565d32ecd3cc5967f32d8c945db6ffba74dc784100777f2" for 127.0.0.1 at 2016-12-15 15:29:59 - 
0800 
I, [2016-12-15T15:29:59.276712 #32520] INFO -- omniauth: (instagram) Callback phase initiated. 
E, [2016-12-15T15:29:59.519801 #32520] ERROR -- omniauth: (instagram) Authentication failure! invalid_credentials: OAuth2::Error, : 
{"code": 400, "error_type": "OAuthException", "error_message": "Matching code was not found or was already used."} 

私は一貫してこれを実現するために得ることができる唯一の方法は、その後、私のアプリからアカウントを接続するInstagramの端から権限を削除し、その後、私のアプリにもう一度再接続しようとすることですが、それはいくつかのように思えます私の顧客は、Instagramアカウントを初めて接続するときにこれを取得しています。

誰でもこれまでに遭遇したことはありますか?私の設定は、/初期化子/ omniauth.rbは、次のようになります。

Rails.application.config.middleware.use OmniAuth::Builder do 
    provider :instagram, ENV['INSTAGRAM_CLIENT_ID'], ENV['INSTAGRAM_CLIENT_SECRET'], scope: 'basic comments public_content' 
end 

編集:私は1.3.1とomniauth-Instagramのをomniauth使用してい

1.0.2

私のルートはあなたの基本的なomniauthルートです:

get '/auth/:provider/callback', to: 'omniauth_callbacks#create' 

そして、私のコントローラのアクションは少し複雑ですが、それは次のようになります。彼らは接続されていない場合は

class OmniauthCallbacksController < ApplicationController 

    def create 
    if user_signed_in? 
     social_account = SocialAccount.from_omniauth(auth_params, current_user) 
     social_account.save! 
     redirect_to root_path 
    else 
     user = User.from_omniauth auth_params 
     sign_in_and_redirect user 
    end 
    end 

    private 

    def auth 
    request.env['omniauth.auth'] 
    end 

    def auth_params 
    { 
     provider: auth['provider'], 
     uid: auth['uid'], 
     token: auth['credentials']['token'], 
     secret: auth['credentials']['secret'] || auth['credentials']['refresh_token'], 
     name: auth['info']['nickname'] || auth['info']['name'], 
     emails_sent: 0 
    } 
    end 
end 

は、基本的には、新しいユーザーや看板それらをを作成し、彼らが持っている場合、それは彼らのログイン情報を更新します。

+0

コールバックを受信するルートファイルやコントローラのような詳細を追加できますか? OmniauthとInstagram Omniauthのどのバージョンを使用していますか? –

+0

@AlexanderLuna私はすべての情報を含む投稿を編集しました。それが役に立ったら教えてください。 – goddamnyouryan

+0

私はより良いアイデアを持っていますが、あなたの "from_omniath"メソッドはどのように見えますか? –

答えて

3

アクセストークンの取得に関するInstagramに問題があるようです。 https://news.ycombinator.com/item?id=13178789

+0

私は解決策は、うまくいけばそれを修正するためにinstagramを待つだけで、その間に顧客がいると思いますWeb上のInstagramのログイン/ログアウトを試みてください。 – goddamnyouryan

+0

時間の100%でさえ機能しません。暗黙的な認証を一時的な修正として使用することを提案する人もいます。 ycombinatorリンクのコメントを確認する –

関連する問題