2022-08-19
1756
#go
Ukeje Goodness
128463
Aug 19, 2022 â‹… 6 min read

A guide to JWT authentication in Go

Ukeje Goodness I am a data analyst who writes about cryptocurrencies and decentralized ledger technologies. Find me on Twitter @Goodylili.

Recent posts:

axios in javascript

Axios in JavaScript: How to make GET, POST, PUT and DELETE requests

Learn how to use Axios in JavaScript for GET, POST, PUT & DELETE requests. Examine setup, error handling, and API best practices.

Faraz Kelhini
Apr 1, 2025 â‹… 19 min read
how AI is shaping the future of 3D web development

How AI is shaping the future of 3D web development

AI for 3D web development is taking the internet by storm. Learn about this trend, the best tools for 3D web experiences, and how it’ll affect the development landscape moving forward.

Elijah Asaolu
Apr 1, 2025 â‹… 5 min read
docker exit code 1

How to troubleshoot exit code 1 in Docker

exit code 1 is one of the most common and frustrating errors for developers working in Docker. Explore what it means and how to fix it.

Ukeje Goodness
Apr 1, 2025 â‹… 4 min read
axios vs fetch 2025 update

Axios vs. Fetch (2025 update): Which should you use for HTTP requests?

Fetch() is native, but Axios is powerful. Which should you use in 2025? We compare features, error handling, and performance to help you decide.

Faraz Kelhini
Apr 1, 2025 â‹… 13 min read
View all posts

2 Replies to "A guide to JWT authentication in Go"

  1. Your code is incorrect. You should be returning the secret key on the happy path of the jwt.Parse function, not an empty string. Returning an empty string results in getting an error from the jwt.Parse function. Here is the correct implementation for anybody that was stuck on this as me:

    token, err := jwt.Parse(r.Header[“Token”][0], func(token *jwt.Token) (interface{}, error) {
    if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
    return “”, fmt.Errorf(“Unexpected signing method: %v”, token.Header[“alg”])
    }
    return sampleSecretKey, nil
    })

Leave a Reply