go-oauth2 / oauth2

OAuth 2.0 server library for the Go programming language.
https://pkg.go.dev/github.com/go-oauth2/oauth2/v4
MIT License
3.31k stars 563 forks source link

The key disconnect I had was understanding the expected flow of my app. #218

Open wilsonlichina opened 2 years ago

wilsonlichina commented 2 years ago

The key disconnect I had was understanding the expected flow of my app. After I dug around in the api and saw the implementation I figured out what the path was and could debug properly to get everything working.

Everything is working, sorry for the question.

On Mon, Mar 25, 2019 at 9:06 PM Lyric notifications@github.com wrote:

I tried to understand your needs. Do you want to use password mode to generate an access token with JWT? If so, the rough process is this (also in the example):

    manager := manage.NewDefaultManager()

manager.SetAuthorizeCodeTokenCfg(manage.DefaultAuthorizeCodeTokenCfg)

// token store manager.MustTokenStorage(store.NewMemoryTokenStore())

// generate jwt access token manager.MapAccessGenerate(generates.NewJWTAccessGenerate([]byte("00000000"), jwt.SigningMethodHS512))

clientStore := store.NewClientStore() clientStore.Set("222222", &models.Client{ ID: "222222", Secret: "22222222", Domain: "http://localhost:9094", }) manager.MapClientStorage(clientStore)

srv := server.NewServer(server.NewConfig(), manager)

srv.SetPasswordAuthorizationHandler(func(username, password string) (userID string, err error) { if username == "test" && password == "test" { userID = "test" } return })

Parse and verify jwt access token

token, err := jwt.ParseWithClaims(access, &generates.JWTAccessClaims{}, func(t jwt.Token) (interface{}, error) { if _, ok := t.Method.(jwt.SigningMethodHMAC); !ok { return nil, fmt.Errorf("parse error") } return []byte("00000000"), nil })if err != nil { // panic(err) } claims, ok := token.Claims.(*generates.JWTAccessClaims)if !ok || !token.Valid { // panic("invalid token") }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/go-oauth2/oauth2/issues/100#issuecomment-476467680, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1ok84IjgVKGCNWgyZPgk48ahI4fi9Dks5vaZzhgaJpZM4cKceN .

Originally posted by @mikepc in https://github.com/go-oauth2/oauth2/issues/100#issuecomment-476929889

wilsonlichina commented 2 years ago

hello mike, can you show your code for reigster/login implemention?