条带回调重定向http而不是https uri

时间:2015-09-02 10:58:35

标签: ruby-on-rails stripe-payments stripe-connect

我在我的网站上使用条带连接,当生产中的用户尝试将他的条带帐户连接到我的网站时,我在条带回调中出现以下错误:

{
  "error": "invalid_redirect_uri",
  "error_description": "Invalid redirect URI 'http://www.mywebsite.com/stripe_connections/callback'. Ensure this uri exactly matches one of the uris specified in your application settings",
  "state": "4 »
}  

而我的条带应用程序设置中的redirecti URIS是https://www.mywebsite.com/stripe_connections/callback

这是我的控制器:

  require 'oauth2'

  class StripeConnectionsController < ApplicationController
    skip_after_action :verify_authorized

    def new
      stripe_auth_url = "https://connect.stripe.com/oauth"
      client = OAuth2::Client.new(ENV['STRIPE_CONNECT_CLIENT_ID'], ENV['STRIPE_SECRET_KEY'], :site => stripe_auth_url)
      @stripe_url = client.auth_code.authorize_url(:redirect_uri => "#{request.protocol}#{request.host_with_port}/stripe_connections/callback", :scope => 'read_write', state: params[:brief_id])
    end

    def callback
      @brief = Brief.find(params[:state])
      stripe_auth_url = "https://connect.stripe.com/oauth"
      @user = current_user
      client = OAuth2::Client.new(ENV['STRIPE_CONNECT_CLIENT_ID'], ENV['STRIPE_SECRET_KEY'], :site => stripe_auth_url)
      access_token = client.auth_code.get_token(params[:code], :redirect_uri => '#{request.protocol}#{request.host_with_port}/oauth2/callback')
      stripe_connection = StripeConnection.find_or_create_by(user_id: @user.id)
      stripe_connection.update_attributes(access_token: access_token.token,
                                          refresh_token: access_token.refresh_token,
                                          livemode: access_token.params['livemode'],
                                          stripe_user_id: access_token.params['stripe_user_id'],
                                          publishable_key: access_token.params['stripe_publishable_key']
                                          )
      @user.profile.projects.where(state: 'pending').update_all(state: "on_sale")
    end
  end

我正在使用heroku并且已经支付了SSL加载项。 我不知道为什么条带返回http而不是https。有没有人有想法? THX。

ps:这在生产之前已经有效,并且可以在网站的测试版中使用

2 个答案:

答案 0 :(得分:0)

您是否有用户点击以连接到条带的按钮?我刚删除了redirect_uri参数。

答案 1 :(得分:0)

您必须删除redirect_uri方法中的client.auth_code.authorize_url() new以及redirect_uri方法中的callback,并将正确的协议放入仪表板条纹。