Coder Social home page Coder Social logo

Comments (9)

hassanrbh avatar hassanrbh commented on September 25, 2024 2

#63 here is the implementation and also something is wrong in repository, needs Cognitive Complexity of 5, but I am exceeding in it, I write a custom tokenscontroller and registration controller and also authentication controller, to get yourself ready as fast as possible, is combining the three response methods, I am storing the refresh token in the cookie with ( jit as a keyword) and leaving the access token in the headers because in the frontend, I will store it, in the state using redux and access it from the state and do my logic and when you signed in or signed up, I am returning the access token in the response body

from api_guard.

gczh avatar gczh commented on September 25, 2024

Managed to do some workarounds for now but it's a shoddy approach.

CleanShot 2021-04-04 at 12 10 05@2x

Overrode AuthenticationController and set the access + refresh tokens after it's generated and set in the headers by api_guard.

I took a look at the gem's core code further and I think we could probably add support for HTTP Only Cookie as an alternative to using Request Headers.

My suggestion is to:

  • Refactor create_token_and_set_header(resource, resource_name) to create_token_and_set_in_strategy
  • Add a create_token_and_set_in_strategy to allow users to specify which strategy they'd like: Http Only Cookie or Request Headers, or both
  • Allow users to specify the configuration in api_guard.rb initializer file. Some users might want to have both Request Headers and http only cookie support?

Would love to give this a try if you're open to it.

from api_guard.

Gokul595 avatar Gokul595 commented on September 25, 2024

@gczh Thanks for your suggestion, it looks good.

We need to support three ways of sending tokens in response:

I am also thinking about using the access & refresh tokens from cookies (if present) for authenticating the request when Authorization header is missing in the request. It would be better if you can add this too. We are accessing the tokens in below listed places:

  • ApiGuard::JwtAuth::Authentication#authenticate_and_set_resources
  • ApiGuard::TokensController#find_refresh_token
  • lib/generators/api_guard/controllers/templates/tokens_controller.rb

Let me know if you are willing to do these changes.

from api_guard.

gczh avatar gczh commented on September 25, 2024

Happy to tackle this if you're up to code review my changes(:

from api_guard.

Gokul595 avatar Gokul595 commented on September 25, 2024

Yes. I can. Please proceed 👍

from api_guard.

gczh avatar gczh commented on September 25, 2024

Yes. I can. Please proceed 👍

Will work on this!

from api_guard.

mdodell avatar mdodell commented on September 25, 2024

Is there any update on this, cc @Gokul595?

from api_guard.

hassanrbh avatar hassanrbh commented on September 25, 2024

I got refresh tokens in cookies working in my startup, I am gonna fork the repository and start working on it :)

from api_guard.

hassanrbh avatar hassanrbh commented on September 25, 2024

and also I think we need to make the http cookie implementation default ?

from api_guard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.