LoginSignup
onomimono
@onomimono (Yusuke Hidaka)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

LINEログインのリダイレクトURLが本番環境だけ合わない。Invalid redirect_uri value. Check if it is registered in a LINE developers site.

前提・実現したいこと

WebサービスからLINEログインをさせて、自前のUserIDとLINEのuser_idを紐づけたい。

発生している問題・エラーメッセージ

ngrokを使ってのLINEログインは成功するが、本番環境でだけ以下のエラーが発生する。
Invalid redirect_uri value. Check if it is registered in a LINE developers site.
image.png

リダイレクトURLは以下2つ
https://3rd-shutter.com/auth/line_model/callback
https://5049d4817541.ngrok.io/auth/line_model/callback
※ngrokの方は既にポートを閉じています。
image.png

該当コード

application.rb
# gem 'line-bot-api'を使えるように宣言
require 'line/bot'

def client_model
  @client_model ||= Line::Bot::Client.new { |config|
    config.channel_id = "hogehoge"
    config.channel_secret = "hogehoge"
    config.channel_token = "hogehoge"
  }
end
model_users_controller.rb
def line_model
    if current_model_user
      current_model_user.update(line_user_id: request.env["omniauth.auth"]["uid"], line_user_token:request.env["omniauth.auth"]["credentials"]["token"]) 

      message = {
        type: 'text',
        text: "LINE連携が完了しました!\nこれから重要な通知のみLINEに届きます!"
      }
      response = client_model.push_message(request.env["omniauth.auth"]["uid"], message)


      flash.alert = 'LINE連携が完了しました。友達追加がうまくいかなった方は、「LINE友達追加」から友達追加してください。'
      redirect_to model_user_path(current_model_user.id)
    else
      flash.alert = 'ログインしてください'
      redirect_to root_path
    end
  end
routes.rb
Rails.application.routes.draw do
  get "/auth/line_model/callback" => "model_users#line_model"
end

補足情報(FW/ツールのバージョンなど)

この記事を参考に実装しました。
https://qiita.com/YuitoSato/items/a9e613370f418d5c322c

【環境】
Rails6
さくらのVPSサーバー
gem 'omniauth-line'
https://qiita.com/MasamotoMiyata/items/ccc932e96a4f5dd6c2e1

0

No Answers yet.

Your answer might help someone💌