简体   繁体   中英

stripe callback redirecting http instead https uri

I'm using stripe connect on my website, and when a user in production tries to connect his stripe account to my web site, I have the following error in the stripe callback :

{
  "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 »
}  

whereas my redirecti URIS in my stripe application setting is https://www.mywebsite.com/stripe_connections/callback

here is my controller :

  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

I'm using heroku and paying the SSL add-ons already. I don't know why stripe is returning http instead of https. Does anyone have an idea? thx.

ps: this has already worked before in production and works in the beta version of the website

Do you have a button that the user clicks to connect to stripe? I just removed the redirect_uri parameter.

您必须在new方法中删除client.auth_code.authorize_url()redirect_uri ,在callback方法中还要删除redirect_uriclient.auth_code.authorize_url()client.auth_code.authorize_url()中放置正确的协议。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM