mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 16:32:13 +08:00

* wip * wip + tests * wip * wip opt2 * Use authn.Identity struct's SessionToken * Merge fixes * Handle disabling the feature flag correctly * Fix test * Cleanup * Remove HasOAuthEntry from the OAuthTokenService interface * Remove unused function
39 lines
1016 B
Go
39 lines
1016 B
Go
package oauthtokentest
|
|
|
|
import (
|
|
"context"
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
|
"github.com/grafana/grafana/pkg/services/auth"
|
|
"github.com/grafana/grafana/pkg/services/datasources"
|
|
"github.com/grafana/grafana/pkg/services/oauthtoken"
|
|
)
|
|
|
|
// Service an OAuth token service suitable for tests.
|
|
type Service struct {
|
|
Token *oauth2.Token
|
|
}
|
|
|
|
// ProvideService provides an OAuth token service suitable for tests.
|
|
func ProvideService() *Service {
|
|
return &Service{}
|
|
}
|
|
|
|
func (s *Service) GetCurrentOAuthToken(context.Context, identity.Requester, *auth.UserToken) *oauth2.Token {
|
|
return s.Token
|
|
}
|
|
|
|
func (s *Service) IsOAuthPassThruEnabled(ds *datasources.DataSource) bool {
|
|
return oauthtoken.IsOAuthPassThruEnabled(ds)
|
|
}
|
|
|
|
func (s *Service) TryTokenRefresh(context.Context, identity.Requester, *auth.UserToken) (*oauth2.Token, error) {
|
|
return s.Token, nil
|
|
}
|
|
|
|
func (s *Service) InvalidateOAuthTokens(context.Context, identity.Requester, *auth.UserToken) error {
|
|
return nil
|
|
}
|