mirror of
				https://github.com/aler9/gortsplib
				synced 2025-11-01 02:52:36 +08:00 
			
		
		
		
	 f283abc2e7
			
		
	
	f283abc2e7
	
	
	
		
			
			(https://github.com/bluenviron/mediamtx/issues/3116) This fixes authentication issues with some TP-LINK cameras.
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package auth
 | |
| 
 | |
| import (
 | |
| 	"github.com/bluenviron/gortsplib/v4/pkg/base"
 | |
| 	"github.com/bluenviron/gortsplib/v4/pkg/headers"
 | |
| )
 | |
| 
 | |
| // GenerateWWWAuthenticate generates a WWW-Authenticate header.
 | |
| func GenerateWWWAuthenticate(methods []ValidateMethod, realm string, nonce string) base.HeaderValue {
 | |
| 	if methods == nil {
 | |
| 		methods = []ValidateMethod{ValidateMethodBasic, ValidateMethodDigestMD5, ValidateMethodSHA256}
 | |
| 	}
 | |
| 
 | |
| 	var ret base.HeaderValue
 | |
| 
 | |
| 	for _, m := range methods {
 | |
| 		var a base.HeaderValue
 | |
| 
 | |
| 		switch m {
 | |
| 		case ValidateMethodBasic:
 | |
| 			a = headers.Authenticate{
 | |
| 				Method: headers.AuthMethodBasic,
 | |
| 				Realm:  realm,
 | |
| 			}.Marshal()
 | |
| 
 | |
| 		case ValidateMethodDigestMD5:
 | |
| 			aa := headers.AuthAlgorithmMD5
 | |
| 			a = headers.Authenticate{
 | |
| 				Method:    headers.AuthMethodDigest,
 | |
| 				Realm:     realm,
 | |
| 				Nonce:     nonce,
 | |
| 				Algorithm: &aa,
 | |
| 			}.Marshal()
 | |
| 
 | |
| 		default: // sha256
 | |
| 			aa := headers.AuthAlgorithmSHA256
 | |
| 			a = headers.Authenticate{
 | |
| 				Method:    headers.AuthMethodDigest,
 | |
| 				Realm:     realm,
 | |
| 				Nonce:     nonce,
 | |
| 				Algorithm: &aa,
 | |
| 			}.Marshal()
 | |
| 		}
 | |
| 
 | |
| 		ret = append(ret, a...)
 | |
| 	}
 | |
| 
 | |
| 	return ret
 | |
| }
 |