mirror of
https://github.com/grafana/grafana.git
synced 2025-01-01 11:47:05 -06:00
Chore: Remove bus from oauthtoken (#46811)
This commit is contained in:
parent
45745debe5
commit
9315ddd57c
@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/login/social"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
@ -16,7 +16,8 @@ var (
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
SocialService social.Service
|
||||
SocialService social.Service
|
||||
AuthInfoService login.AuthInfoService
|
||||
}
|
||||
|
||||
type OAuthTokenService interface {
|
||||
@ -24,9 +25,10 @@ type OAuthTokenService interface {
|
||||
IsOAuthPassThruEnabled(*models.DataSource) bool
|
||||
}
|
||||
|
||||
func ProvideService(socialService social.Service) *Service {
|
||||
func ProvideService(socialService social.Service, authInfoService login.AuthInfoService) *Service {
|
||||
return &Service{
|
||||
SocialService: socialService,
|
||||
SocialService: socialService,
|
||||
AuthInfoService: authInfoService,
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +40,7 @@ func (o *Service) GetCurrentOAuthToken(ctx context.Context, user *models.SignedI
|
||||
}
|
||||
|
||||
authInfoQuery := &models.GetAuthInfoQuery{UserId: user.UserId}
|
||||
if err := bus.Dispatch(ctx, authInfoQuery); err != nil {
|
||||
if err := o.AuthInfoService.GetAuthInfo(ctx, authInfoQuery); err != nil {
|
||||
if errors.Is(err, models.ErrUserNotFound) {
|
||||
// Not necessarily an error. User may be logged in another way.
|
||||
logger.Debug("no OAuth token for user found", "userId", user.UserId, "username", user.Login)
|
||||
@ -88,7 +90,7 @@ func (o *Service) GetCurrentOAuthToken(ctx context.Context, user *models.SignedI
|
||||
AuthId: authInfoQuery.Result.AuthId,
|
||||
OAuthToken: token,
|
||||
}
|
||||
if err := bus.Dispatch(ctx, updateAuthCommand); err != nil {
|
||||
if err := o.AuthInfoService.UpdateAuthInfo(ctx, updateAuthCommand); err != nil {
|
||||
logger.Error("failed to update auth info during token refresh", "userId", user.UserId, "username", user.Login, "error", err)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user