Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API versioning the devise scope of token validation and ominiauth controller path will wrap up #96

Closed
vs-zhang opened this issue Dec 29, 2014 · 7 comments

Comments

@vs-zhang
Copy link

Hi @lynndylanhurley

First of all, thank's for making this gem. It make my life more easier.

But when i tried to use API versioning and i put mount_devise_token_auth_for 'User', at: '/auth' inside the namespace :api and scope :v1, the route of token validation and ominiauth will add api/v1, to the beginning.

routes.rb:

  namespace :api, defaults: {format: :json} do
    scope module: :v1, constraints: ApiConstraints.new(version: 1, default: :true) do
      mount_devise_token_auth_for 'User', at: '/auth', skip: [:confirmations]
    end
  end

and the route will be

 api_validate_token GET      /api/auth/validate_token(.:format)     api/v1/devise_token_auth/token_validations#validate_token {:format=>:json}
                 api_failure GET      /api/auth/failure(.:format)            api/v1/devise_token_auth/omniauth_callbacks#omniauth_failure {:format=>:json}
                         api GET      /api/auth/:provider/callback(.:format) api/v1/devise_token_auth/omniauth_callbacks#omniauth_success {:format=>:json}

I think it should be without the api/v1 in the controller path

@lynndylanhurley
Copy link
Owner

@vs-zhang - try un-nesting the mount_devise_token_auth_for method from the namespace, and spelling out the entire namespace in the at param.

Something like this:

namespace :api, defaults: {format: :json} do
  scope module: :v1, constraints: ApiConstraints.new(version: 1, default: :true) do
    # add the rest of your versioned routes here
  end
end

# mount the auth routes outside of the namespace
mount_devise_token_auth_for 'User', at: '/api/v1/auth'

I haven't been able to get devise to cooperate with namespaces or scopes from within my gem. Spelling out the full path in the at param seems to be the only way to make it work.

But this situation may have changed since I last tried. I'll look into solving this issue for the next release.

@vs-zhang
Copy link
Author

Yes, I un-nesting and only use one scope for now

  scope '/api', defaults: {format: :json} do
    mount_devise_token_auth_for 'User', at: '/auth'
  end

And it works but not for versioning, just want to point it out.

@lynndylanhurley
Copy link
Owner

@vs-zhang - I just pushed an update that may fix your nesting issue. Please update to version 0.1.31.beta2 and let me know if it works for you.

@lynndylanhurley
Copy link
Owner

This is the route configuration that I'm using in the tests, and it's passing:

Rails.application.routes.draw do
  # ...

  namespace :api do
    scope :v1 do
      mount_devise_token_auth_for 'User', at: 'auth'
    end
  end
end

@vs-zhang
Copy link
Author

vs-zhang commented Jan 6, 2015

@lynndylanhurley I am using a fork version of mongoid, i will make the change and test it later. When i get more time late, hope i can contribute more for the mongoid version.

@lynndylanhurley
Copy link
Owner

@vs-zhang - 0.1.31.beta2 had issues. Try out version 0.1.31.beta7 instead if you can.

@booleanbetrayal
Copy link
Collaborator

Closing due to inactivity. Can re-open as needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants