-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Usage with Grape #73
Comments
@ColbyAley - have you tried it and found that it's not working, or is this a general inquiry? |
@lynndylanhurley It's a general inquiry. I'm currently working on doing it manually, but I'm wondering if there are any existing resources. If not, I'll be sure to share what I learn. |
I don't know of anything that would prevent it from working. Let me know how it goes if you decide to try it! |
I'm gonna close this one out for now. Please re-open if you run into any issues! |
I'm having the same issue. When using Grape for API, we don't use Controllers, so I'm not able to do this: class ApplicationController < ActionController::Base
include DeviseTokenAuth::Concerns::SetUserByToken
end The user is not set and we get 401. :( I tried to copy the methods from the Concern and paste it to Grape's helpers and to run the What else could I do to make it work? |
@rajaaa92 I ended up butchering some of the code from
Then, in Grape (in my case,
This seems to work for me, but I pared it down quite a bit so it doesn't currently work with batched requests, and probably some other features I'm not currently using. |
Thanks @ColbyAley ! It looks like it's working! :) For now I don't need batched requests so your code is enough for me. Thanks again :) |
I also have the same setup as you are. I am wondering where in the grape you have I know you mentioned Or you actually added the custom class and added before and after blocks Grape repo or to your rails project? Thanks |
My class API < Grape::API
format :json
formatter :json, Grape::Formatter::ActiveModelSerializers
logger Rails.logger
mount ::V1::Base
end My require 'authenticated_request'
module V1
class Base < Grape::API
version 'v1', using: :path
before do
next if @resource
@req = ::AuthenticatedRequest.new(
uid: request.headers['Uid'],
token: request.headers['Access-Token'],
client: request.headers['Client'],
resource: @resource
)
@resource = @req.begin
if @resource
env['warden'].set_user(@resource, scope: :user)
else
h = {'Access-Control-Allow-Origin' => "*", 'Access-Control-Request-Method' => %w{GET POST OPTIONS}.join(",")}
error!('You need to log in to use the app.', 401, h)
end
end
mount V1::Something
after do
headers = @req.finish
next if headers.nil?
env['warden'].authenticate(scope: :user)
headers.each{|k,v| header(k,v)}
header 'Access-Control-Allow-Origin', "*"
header 'Access-Control-Request-Method', %w{GET POST OPTIONS}.join(",")
end
end
end The code from I hope that helps! |
Thanks @rajaaa92!! When I get a chance, I'll add a Grape case to the test suite. I don't have much Grape experience - let me know if there's anything this gem can do to provide better support for Grape. |
this is so great, thanks for sharing @rajaaa92! |
👍, it would be nice to use this w/ grape. |
Hi everybody, I created a gem that allows grape to authenticate using an existing devise_token_auth installation in a rails app. Its called grape_devise_token_auth and you can also find an example setup of jToker + devise + devise_token_auth + grape_devise_token_auth here. |
Hi again, So I've created a full port of devise_token_auth for grape. It can be found here at grape_token_auth. This is different from the above gem in that it is purely dependent on grape and does not depend on rails, devise, or devise_token_auth. I'm approaching an initial 0.1.0 release and I'd love it if @lynndylanhurley or @booleanbetrayal could give it a review and tell me what they think. Cheers! |
Fantastic work @mcordell! I'll make a note in the README that directs grape users to your project. |
👍 |
Does anyone have experience using this and ng-token-auth with Grape? I'm looking to access the helpers such as
current_user
in my Grape endpoints.The text was updated successfully, but these errors were encountered: