Skip to content

Commit 2531f4b

Browse files
committed
Updated documentation.
1 parent 7518bd9 commit 2531f4b

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ relation to port exhaustion.
350350
- `ISSUE_INDEXER_PATH`: **indexers/issues.bleve**: Index file used for issue search; available when ISSUE_INDEXER_TYPE is bleve and elasticsearch.
351351
- The next 4 configuration values are deprecated and should be set in `queue.issue_indexer` however are kept for backwards compatibility:
352352
- `ISSUE_INDEXER_QUEUE_TYPE`: **levelqueue**: Issue indexer queue, currently supports:`channel`, `levelqueue`, `redis`.
353-
- `ISSUE_INDEXER_QUEUE_DIR`: **queues/common**: When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this will be the path where the queue will be saved. (Previously this was `indexers/issues.queue`.)
353+
- `ISSUE_INDEXER_QUEUE_DIR`: **queues/common**: When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this will be the path where the queue will be saved. (Previously this was `indexers/issues.queue`.)
354354
- `ISSUE_INDEXER_QUEUE_CONN_STR`: **addrs=127.0.0.1:6379 db=0**: When `ISSUE_INDEXER_QUEUE_TYPE` is `redis`, this will store the redis connection string. When `ISSUE_INDEXER_QUEUE_TYPE` is `levelqueue`, this is a directory or additional options of the form `leveldb://path/to/db?option=value&....`, and overrides `ISSUE_INDEXER_QUEUE_DIR`.
355355
- `ISSUE_INDEXER_QUEUE_BATCH_NUMBER`: **20**: Batch queue number.
356356

@@ -370,7 +370,7 @@ relation to port exhaustion.
370370
## Queue (`queue` and `queue.*`)
371371

372372
- `TYPE`: **persistable-channel**: General queue type, currently support: `persistable-channel` (uses a LevelDB internally), `channel`, `level`, `redis`, `dummy`
373-
- `DATADIR`: **queues/**: Base DataDir for storing persistent and level queues. `DATADIR` for individual queues can be set in `queue.name` sections but will default to `DATADIR/`**`common`**. (Previously each queue would default to `DATADIR/`**`name`**.)
373+
- `DATADIR`: **queues/**: Base DataDir for storing persistent and level queues. `DATADIR` for individual queues can be set in `queue.name` sections but will default to `DATADIR/`**`common`**. (Previously each queue would default to `DATADIR/`**`name`**.)
374374
- `LENGTH`: **20**: Maximal queue size before channel queues block
375375
- `BATCH_LENGTH`: **20**: Batch data before passing to the handler
376376
- `CONN_STR`: **redis://127.0.0.1:6379/0**: Connection string for the redis queue type. Options can be set using query params. Similarly LevelDB options can also be set using: **leveldb://relative/path?option=value** or **leveldb:///absolute/path?option=value**, and will override `DATADIR`
@@ -851,7 +851,9 @@ NB: You must have `DISABLE_ROUTER_LOG` set to `false` for this option to take ef
851851
- `ACCESS_TOKEN_EXPIRATION_TIME`: **3600**: Lifetime of an OAuth2 access token in seconds
852852
- `REFRESH_TOKEN_EXPIRATION_TIME`: **730**: Lifetime of an OAuth2 refresh token in hours
853853
- `INVALIDATE_REFRESH_TOKENS`: **false**: Check if refresh token has already been used
854-
- `JWT_SECRET`: **\<empty\>**: OAuth2 authentication secret for access and refresh tokens, change this a unique string.
854+
- `JWT_SIGNING_ALGORITHM`: **RS256**: Algorithm used to sign OAuth2 tokens. Valid values: \[`HS256`, `HS384`, `HS512`, `RS256`, `RS384`, `RS512`, `ES256`, `ES384`, `ES512`\]
855+
- `JWT_SECRET`: **\<empty\>**: OAuth2 authentication secret for access and refresh tokens, change this to a unique string. This setting is only needed if `JWT_SIGNING_ALGORITHM` is set to `HS256`, `HS384` or `HS512`.
856+
- `JWT_SIGNING_PRIVATE_KEY_FILE`: **jwt/private.pem**: Private key file path used to sign OAuth2 tokens. The path is relative to `CUSTOM_PATH`. This setting is only needed if `JWT_SIGNING_ALGORITHM` is set to `RS256`, `RS384`, `RS512`, `ES256`, `ES384` or `ES512`. The file must contain a RSA or ECDSA private key in the PKCS8 format.
855857
- `MAX_TOKEN_LENGTH`: **32767**: Maximum length of token/cookie to accept from OAuth2 provider
856858

857859
## i18n (`i18n`)

docs/content/doc/developers/oauth2-provider.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ Gitea supports acting as an OAuth2 provider to allow third party applications to
2323

2424
## Endpoints
2525

26-
| Endpoint | URL |
27-
| ---------------------- | --------------------------- |
28-
| Authorization Endpoint | `/login/oauth/authorize` |
29-
| Access Token Endpoint | `/login/oauth/access_token` |
26+
| Endpoint | URL |
27+
| ------------------------ | ----------------------------------- |
28+
| OpenID Connect Discovery | `/.well-known/openid-configuration` |
29+
| Authorization Endpoint | `/login/oauth/authorize` |
30+
| Access Token Endpoint | `/login/oauth/access_token` |
31+
| OpenID Connect UserInfo | `/login/oauth/userinfo` |
32+
| JSON Web Key Set | `/login/oauth/keys` |
3033

3134
## Supported OAuth2 Grants
3235

modules/auth/oauth2/jwtsigningkey.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ func (key hmacSingingKey) VerifyKey() interface{} {
6969
}
7070

7171
func (key hmacSingingKey) ToJWK() (map[string]string, error) {
72-
return map[string]string{}, nil
72+
return map[string]string{
73+
"kty": "oct",
74+
"alg": key.SigningMethod().Alg(),
75+
}, nil
7376
}
7477

7578
type rsaSingingKey struct {
@@ -149,6 +152,8 @@ func (key ecdsaSingingKey) ToJWK() (map[string]string, error) {
149152
}, nil
150153
}
151154

155+
// createPublicKeyFingerprint creates a fingerprint of the given key.
156+
// The fingerprint is the sha256 sum of the PKIX structure of the key.
152157
func createPublicKeyFingerprint(key interface{}) ([]byte, error) {
153158
bytes, err := x509.MarshalPKIXPublicKey(key)
154159
if err != nil {
@@ -214,7 +219,8 @@ func CreateJWTSingingKey(algorithm string, key interface{}) (JWTSigningKey, erro
214219
var DefaultSigningKey JWTSigningKey
215220

216221
// InitSigningKey creates the default signing key from settings or creates a random key.
217-
func InitSigningKey() (err error) {
222+
func InitSigningKey() error {
223+
var err error
218224
var key interface{}
219225

220226
switch setting.OAuth2.JWTSigningAlgorithm {
@@ -243,20 +249,21 @@ func InitSigningKey() (err error) {
243249
}
244250

245251
if err != nil {
246-
log.Error("Error while loading or creating symmetric key: %v", err)
247-
return
252+
return fmt.Errorf("Error while loading or creating symmetric key: %v", err)
248253
}
249254

250255
signingKey, err := CreateJWTSingingKey(setting.OAuth2.JWTSigningAlgorithm, key)
251256
if err != nil {
252-
return
257+
return err
253258
}
254259

255260
DefaultSigningKey = signingKey
256261

257-
return
262+
return nil
258263
}
259264

265+
// loadOrCreateSymmetricKey checks if the configured secret is valid.
266+
// If it is not valid a new secret is created and saved in the configuration file.
260267
func loadOrCreateSymmetricKey() (interface{}, error) {
261268
key := make([]byte, 32)
262269
n, err := base64.RawURLEncoding.Decode(key, []byte(setting.OAuth2.JWTSecretBase64))
@@ -276,6 +283,8 @@ func loadOrCreateSymmetricKey() (interface{}, error) {
276283
return key, nil
277284
}
278285

286+
// loadOrCreateAsymmetricKey checks if the configured private key exists.
287+
// If it does not exist a new random key gets generated and saved on the configured path.
279288
func loadOrCreateAsymmetricKey() (interface{}, error) {
280289
keyPath := setting.OAuth2.JWTSigningPrivateKeyFile
281290

modules/setting/setting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ var (
361361
AccessTokenExpirationTime int64
362362
RefreshTokenExpirationTime int64
363363
InvalidateRefreshTokens bool
364-
JWTSecretBase64 string `ini:"JWT_SECRET"`
365364
JWTSigningAlgorithm string `ini:"JWT_SIGNING_ALGORITHM"`
365+
JWTSecretBase64 string `ini:"JWT_SECRET"`
366366
JWTSigningPrivateKeyFile string `ini:"JWT_SIGNING_PRIVATE_KEY_FILE"`
367367
MaxTokenLength int
368368
}{
@@ -787,7 +787,7 @@ func NewContext() {
787787
}
788788

789789
if !filepath.IsAbs(OAuth2.JWTSigningPrivateKeyFile) {
790-
OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile)
790+
OAuth2.JWTSigningPrivateKeyFile = filepath.Join(CustomPath, OAuth2.JWTSigningPrivateKeyFile)
791791
}
792792

793793
sec = Cfg.Section("admin")

0 commit comments

Comments
 (0)