Giter Site home page Giter Site logo

jwt for api endpoints about auth HOT 12 OPEN

qor avatar qor commented on June 29, 2024
jwt for api endpoints

from auth.

Comments (12)

sergolius avatar sergolius commented on June 29, 2024 1

@x0rzkov
auth module partly supports JWT authentication:

tokenString := req.Header.Get("Authorization")

You can wrap SessionStorer with decorator to extend behaviour of Update method

func (sessionStorer *SessionStorer) Update(w http.ResponseWriter, req *http.Request, claims *claims.Claims) error {

To make set "Authorization" header in response

from auth.

raven-chen avatar raven-chen commented on June 29, 2024

hi @x0rzkov

Do you want to integrate JWT with QOR Admin resources? Or your own handler but with QOR Auth?

from auth.

 avatar commented on June 29, 2024

@raven-chen

Both is it possible ?

But in priority, I want to create an api endpoint with a bearer and allow users to get it with their login credentials (I use auth_themes/clean); not admin users.

So if "Or your own handler but with QOR Auth?" means that so the answer is that.

Btw, it is my second handle of @x0rzkov

Cheers

from auth.

raven-chen avatar raven-chen commented on June 29, 2024

Both are possible. but integrate JWT into QOR Admin is not an easy job.

Since you're in rush. better to do something with the Auth.

type Auth interface {
	GetCurrentUser(*Context) qor.CurrentUser
	LoginURL(*Context) string
	LogoutURL(*Context) string
}

A quick patch would be inserting the jwt logic into GetCurrentUser. I'm not 100% sure it would work but worth a try.

from auth.

 avatar commented on June 29, 2024

@raven-chen

Do you have a snippet to share ? plz

I found that integrating jwt:

from auth.

raven-chen avatar raven-chen commented on June 29, 2024

I don't have a snippet. just an idea. e.g.

func (AdminAuth) GetCurrentUser(c *admin.Context) qor.CurrentUser {
        // this is a normal implementation. You can try embed JWT logic here, if user passes the jwt check, return a proper user. otherwise return nil?
	currentUser := Auth.GetCurrentUser(c.Request)
	if currentUser != nil {
		qorCurrentUser, ok := currentUser.(qor.CurrentUser)
		if !ok {
			fmt.Printf("User %#v haven't implement qor.CurrentUser interface\n", currentUser)
		}
		return qorCurrentUser
	}
	return nil
}

from auth.

 avatar commented on June 29, 2024

@sergolius thanks for your reply :-)

Is there a way to create login controller without the form to get it and/or refresh it ?

Cheers,
X

from auth.

sergolius avatar sergolius commented on June 29, 2024

@x0rzkov QOR is very flexible, it's up to you to extend or override functionality.
See Password provider as base example: https://github.com/qor/auth/blob/11d4c974507d28e2fd10ff94edcdd00369e069a6/providers/password/password.go

from auth.

 avatar commented on June 29, 2024

Unfortunately, I am lost on this one, do not know how to do it... If you have a snippet, you would be my saviour ^^

from auth.

lutfuahmet avatar lutfuahmet commented on June 29, 2024

// TODO write json token

image

from auth.

lutfuahmet avatar lutfuahmet commented on June 29, 2024

I send pull request to auth package.

#45

from auth.

 avatar commented on June 29, 2024

@lutfuahmet do you have an example with the full implementation mate ? Thanks for you reply also, greatly appreciated :-)

from auth.

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.