Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Every request returns a 401 http response with Invalid token #256

Closed
Breigner01 opened this issue Jan 7, 2022 · 1 comment
Closed

Every request returns a 401 http response with Invalid token #256

Breigner01 opened this issue Jan 7, 2022 · 1 comment

Comments

@Breigner01
Copy link

Description

Package Version

v5.21.1

Affected Resources

  • management.User

Sample Code

type User struct {
	UserDB    model.User      `json:"user_db"`
	UserAuth0 management.User `json:"user_auth0"`
}

func getUserByID(c *gin.Context, db *gorm.DB) {
	m, err := management.New(os.Getenv("AUTH0_DOMAIN"), management.WithClientCredentials(
		os.Getenv("AUTH0_CLIENT_ID"),
		os.Getenv("AUTH0_CLIENT_SECRET"),
	))
	if err != nil {
		panic(err)
	}

	var usersDB []model.User
	var users []User

	db.Find(&usersDB)

	for i := range usersDB {
		auth0User, err := m.User.Read(usersDB[i].UserId)
		fmt.Println(err)
		if err != nil {
			c.JSON(500, gin.H{
				"message": "Error getting user from Auth0",
				"error":   err,
			})
			return
		}
		users = append(users, User{
			UserDB:    usersDB[i],
			UserAuth0: *auth0User,
		})
	}

	c.JSON(200, gin.H{
		"user_number": len(users),
		"users":       users,
	})
}

Expected Behavior

I'm expecting it to return the user asked for.

Actual Behavior

I get a 401 http response with the message Unauthorized: Invalid token

Output

401 Unauthorized: Invalid token

References

  • #0000

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@sergiught
Copy link
Collaborator

Closed and cloned this issue to auth0/go-auth0#22

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

No branches or pull requests

2 participants