MCPcopy Create free account
hub / github.com/Quorinex/Kiro-Go / apiRefreshAccount

Method apiRefreshAccount

proxy/handler.go:3202–3301  ·  view source on GitHub ↗

apiRefreshAccount 刷新账户信息(使用量、订阅等)

(w http.ResponseWriter, r *http.Request, id string)

Source from the content-addressed store, hash-verified

3200 w.WriteHeader(http.StatusBadRequest)
3201 json.NewEncoder(w).Encode(map[string]string{"error": "Invalid JSON"})
3202 return
3203 }
3204 sessionID := strings.TrimSpace(req.SessionID)
3205 selectionID := strings.TrimSpace(req.SelectionID)
3206 if sessionID == "" && selectionID != "" {
3207 if selection := h.getMicrosoftProfileSelection(selectionID); selection != nil {
3208 sessionID = selection.SessionID
3209 }
3210 }
3211 if sessionID != "" {
3212 h.markMicrosoftSessionCanceled(sessionID)
3213 }
3214 auth.CancelMicrosoftSSOLogin(sessionID)
3215 if selectionID != "" {
3216 h.removeMicrosoftProfileSelection(selectionID, nil)
3217 }
3218 if sessionID != "" {
3219 h.removeMicrosoftProfileSelectionsForSession(sessionID)
3220 }
3221 json.NewEncoder(w).Encode(map[string]bool{"success": true})
3222}
3223
3224func (h *Handler) storeMicrosoftProfileSelection(
3225 sessionID string,
3226 account config.Account,
3227 profiles []KiroProfile,
3228) (string, []*microsoftProfileSelection, error) {
3229 now := time.Now()
3230 expiresAt := now.Add(microsoftProfileSelectionTTL)
3231 tokenExpiry := time.Unix(account.ExpiresAt, 0)
3232 if account.ExpiresAt > 0 && tokenExpiry.Before(expiresAt) {
3233 expiresAt = tokenExpiry
3234 }
3235 if !expiresAt.After(now) {
3236 return "", nil, fmt.Errorf("Microsoft credential expired before profile selection")
3237 }
3238 selectionID := uuid.NewString()
3239 selection := &microsoftProfileSelection{
3240 SessionID: strings.TrimSpace(sessionID),
3241 Account: account,
3242 Profiles: append([]KiroProfile(nil), profiles...),
3243 ExpiresAt: expiresAt,
3244 }
3245 var expired []*microsoftProfileSelection
3246
3247 h.microsoftSelectionsMu.Lock()
3248 if h.microsoftSelections == nil {
3249 h.microsoftSelections = make(map[string]*microsoftProfileSelection)
3250 }
3251 for id, current := range h.microsoftSelections {
3252 if !now.Before(current.ExpiresAt) {
3253 delete(h.microsoftSelections, id)
3254 current.canceled.Store(true)
3255 if current.timer != nil {
3256 current.timer.Stop()
3257 current.timer = nil
3258 }
3259 expired = append(expired, current)

Callers 1

handleAdminAPIMethod · 0.95

Calls 8

GetAccountsFunction · 0.92
RefreshTokenFunction · 0.92
UpdateAccountTokenFunction · 0.92
UpdateAccountProfileArnFunction · 0.92
UpdateAccountInfoFunction · 0.92
RefreshAccountInfoFunction · 0.85
UpdateTokenMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected