MCPcopy
hub / github.com/tinyauthapp/tinyauth / NewOAuthSession

Method NewOAuthSession

internal/service/auth_service.go:615–646  ·  view source on GitHub ↗
(serviceName string, params OAuthURLParams)

Source from the content-addressed store, hash-verified

613}
614
615func (auth *AuthService) NewOAuthSession(serviceName string, params OAuthURLParams) (string, OAuthPendingSession, error) {
616 auth.ensureOAuthSessionLimit()
617
618 service, ok := auth.oauthBroker.GetService(serviceName)
619
620 if !ok {
621 return "", OAuthPendingSession{}, fmt.Errorf("oauth service not found: %s", serviceName)
622 }
623
624 sessionId, err := uuid.NewRandom()
625
626 if err != nil {
627 return "", OAuthPendingSession{}, fmt.Errorf("failed to generate session ID: %w", err)
628 }
629
630 state := service.NewRandom()
631 verifier := service.NewRandom()
632
633 session := OAuthPendingSession{
634 State: state,
635 Verifier: verifier,
636 Service: &service,
637 ExpiresAt: time.Now().Add(1 * time.Hour),
638 CallbackParams: params,
639 }
640
641 auth.oauthMutex.Lock()
642 auth.oauthPendingSessions[sessionId.String()] = &session
643 auth.oauthMutex.Unlock()
644
645 return sessionId.String(), session, nil
646}
647
648func (auth *AuthService) GetOAuthURL(sessionId string) (string, error) {
649 session, err := auth.GetOAuthPendingSession(sessionId)

Callers 1

oauthURLHandlerMethod · 0.80

Calls 3

GetServiceMethod · 0.80
NewRandomMethod · 0.65

Tested by

no test coverage detected