Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
40
backend/sdk/cliproxy/auth/metadata_merge.go
Normal file
40
backend/sdk/cliproxy/auth/metadata_merge.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// IsAuthTokenPayloadKey returns true if key is a credential or token lifecycle field
|
||||
// that should not overwrite newly acquired OAuth credentials during metadata merge.
|
||||
func IsAuthTokenPayloadKey(key string) bool {
|
||||
switch strings.ToLower(strings.TrimSpace(key)) {
|
||||
case "access_token", "refresh_token", "id_token", "session_id",
|
||||
"expired", "last_refresh", "expires_in", "timestamp",
|
||||
"token_type", "user_code", "verification_uri", "verification_uri_complete":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// MergeExistingAuthMetadata merges user-configured metadata fields from existingMap
|
||||
// into target.Metadata and target.Storage if target does not already define them.
|
||||
func MergeExistingAuthMetadata(target *Auth, existingMap map[string]any) {
|
||||
if target == nil || len(existingMap) == 0 {
|
||||
return
|
||||
}
|
||||
if target.Metadata == nil {
|
||||
target.Metadata = make(map[string]any)
|
||||
}
|
||||
for k, v := range existingMap {
|
||||
if IsAuthTokenPayloadKey(k) {
|
||||
continue
|
||||
}
|
||||
if _, exists := target.Metadata[k]; !exists {
|
||||
target.Metadata[k] = v
|
||||
}
|
||||
}
|
||||
if setter, ok := target.Storage.(interface{ SetMetadata(map[string]any) }); ok {
|
||||
setter.SetMetadata(target.Metadata)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue