Skip to content

Commit 12f1b31

Browse files
committed
Added more stuff from old README
1 parent 0bc1aae commit 12f1b31

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

docs/index.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,14 @@ Then import it in your code:
4141

4242
```go
4343
import "github.com/golang-jwt/jwt/v5"
44-
```
44+
```
45+
46+
## JWT and OAuth 2.0
47+
48+
It's worth mentioning that OAuth and JWT are not the same thing. A JWT token is simply a signed JSON object. It can be used anywhere such a thing is useful. There is some confusion, though, as JWT is the most common type of bearer token used in OAuth2 authentication.
49+
50+
Without going too far down the rabbit hole, here's a description of the interaction of these technologies:
51+
52+
* OAuth is a protocol for allowing an identity provider to be separate from the service a user is logging in to. For example, whenever you use Facebook to log into a different service (Yelp, Spotify, etc), you are using OAuth.
53+
* OAuth defines several options for passing around authentication data. One popular method is called a "bearer token". A bearer token is simply a string that should only be held by an authenticated user. Thus, simply presenting this token proves your identity. You can probably derive from here why a JWT might make a good bearer token. This is also specified in the JSON Web Token (JWT) Profile for OAuth 2.0 Access Tokens, detailed in [RFC 9068](https://datatracker.ietf.org/doc/html/rfc9068).
54+
* Because bearer tokens are used for authentication, it's important they're kept secret. This is why transactions that use bearer tokens typically happen over TLS.

docs/usage/signing_methods.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Signing Methods
22

3+
## Signing vs Encryption
4+
5+
A token is simply a JSON object that is signed by its author. this tells you exactly two things about the data:
6+
7+
* The author of the token was in the possession of the signing secret
8+
* The data has not been modified since it was signed
9+
10+
It's important to know that JWT does not provide encryption, which means anyone who has access to the token can read its contents. If you need to protect (encrypt) the data, there is a companion spec, JSON Web Encryption (JWT)[^jwe], that provides this functionality. The companion project [https://github.com/golang-jwt/jwe](https://github.com/golang-jwt/jwe) aims at a (very) experimental implementation of the JWE standard.
11+
12+
## Choosing a Signing Method
13+
314
There are several signing methods available, and you should probably take the time to learn about the various options before choosing one. The principal design decision is most likely going to be **symmetric** vs **asymmetric**.
415

516
Symmetric signing methods, such as HMAC, use only a single secret. This is probably the simplest signing method to use since any `[]byte` can be used as a valid secret. They are also slightly computationally faster to use, though this rarely is enough to matter. Symmetric signing methods work the best when both producers and consumers of tokens are trusted, or even the same system. Since the same secret is used to both sign and validate tokens, you can't easily distribute the key for validation.
@@ -18,6 +29,7 @@ Each signing method expects a different object type for its signing keys. The fo
1829
| [RSA-PSS signing method](https://pkg.go.dev/github.com/golang-jwt/jwt/v5#SigningMethodRSAPSS)[^rsapss] | `PS256`,`PS384`,`PS512` | [`*rsa.PrivateKey`](https://pkg.go.dev/crypto/rsa#PrivateKey) | [`*rsa.PublicKey`](https://pkg.go.dev/crypto/rsa#PublicKey) |
1930
| [EdDSA signing method](https://pkg.go.dev/github.com/golang-jwt/jwt/v5#SigningMethodEd25519)[^eddsa] | `Ed25519` | [`ed25519.PrivateKey`](https://pkg.go.dev/crypto/ed25519#PrivateKey) | [`ed25519.PublicKey`](https://pkg.go.dev/crypto/ed25519#PublicKey) |
2031

32+
[^jwe]: [RFC 7516](https://datatracker.ietf.org/doc/html/rfc7516)
2133
[^hmac]: [Section 3.2 of RFC 7518](https://datatracker.ietf.org/doc/html/rfc7518#section-3.2)
2234
[^rsa]: [Section 3.2 of RFC 7518](https://datatracker.ietf.org/doc/html/rfc7518#section-3.3)
2335
[^ecdsa]: [Section 3.2 of RFC 7518](https://datatracker.ietf.org/doc/html/rfc7518#section-3.4)

0 commit comments

Comments
 (0)