Search code examples
ruby-on-railsember.jscorsomniauthaccess-control

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access


I am trying to use omniauth to direct my client to an external services authorization page. My client uses ember.js and my server is a rails server. As things stand, I am able to make the call with little problem on my server side, but my client will not redirect, thoring me an error reading

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 404.

Doing some research has shown that I need to use CORS, which I have installed and configured. Now I just need to know where and how I apply the access-control-allow-origin header to my code. Can anyone help me with this problem?

my route:

get 'auth/:provider/callback' => 'sessions#create'

my sessions controller:

class SessionsController < ApplicationController
  def create
    @request.env
    auth = request.env['omniauth.auth']
    Account.recieve_donation(auth)
  end
end

Solution

  • Here is what you will have to do If you are making GET request, your client request have to send Origin header and then your server have to send the Access-Control-Allow-Origin header in the response. Values of both of these header have to be the same to allow cross origin resource sharing.