mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Allow for PKCE flow without client secret + add docs (#25033)
The PKCE flow according to [RFC 7636](https://datatracker.ietf.org/doc/html/rfc7636) allows for secure authorization without the requirement to provide a client secret for the OAuth app. It is implemented in Gitea since #5378 (v1.8.0), however without being able to omit client secret. Since #21316 Gitea supports setting client type at OAuth app registration. As public clients are already forced to use PKCE since #21316, in this PR the client secret check is being skipped if a public client is detected. As Gitea seems to implement PKCE authorization correctly according to the spec, this would allow for PKCE flow without providing a client secret. Also add some docs for it, please check language as I'm not a native English speaker. Closes #17107 Closes #25047
This commit is contained in:
		@@ -695,7 +695,7 @@ func handleRefreshToken(ctx *context.Context, form forms.AccessTokenForm, server
 | 
			
		||||
	}
 | 
			
		||||
	// "The authorization server MUST ... require client authentication for confidential clients"
 | 
			
		||||
	// https://datatracker.ietf.org/doc/html/rfc6749#section-6
 | 
			
		||||
	if !app.ValidateClientSecret([]byte(form.ClientSecret)) {
 | 
			
		||||
	if app.ConfidentialClient && !app.ValidateClientSecret([]byte(form.ClientSecret)) {
 | 
			
		||||
		errorDescription := "invalid client secret"
 | 
			
		||||
		if form.ClientSecret == "" {
 | 
			
		||||
			errorDescription = "invalid empty client secret"
 | 
			
		||||
@@ -753,7 +753,7 @@ func handleAuthorizationCode(ctx *context.Context, form forms.AccessTokenForm, s
 | 
			
		||||
		})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if !app.ValidateClientSecret([]byte(form.ClientSecret)) {
 | 
			
		||||
	if app.ConfidentialClient && !app.ValidateClientSecret([]byte(form.ClientSecret)) {
 | 
			
		||||
		errorDescription := "invalid client secret"
 | 
			
		||||
		if form.ClientSecret == "" {
 | 
			
		||||
			errorDescription = "invalid empty client secret"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user