mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-07 11:58:12 +02:00
## Summary This adds the necessary logic needed for device auth flow in ssh. The code is not used currently; will follow up with testenv updates that can let us test this with the mock idp. ## Related issues <!-- For example... - #159 --> ## User Explanation <!-- How would you explain this change to the user? If this change doesn't create any user-facing changes, you can leave this blank. If filled out, add the `docs` label --> ## Checklist - [ ] reference any related issues - [ ] updated unit tests - [ ] add appropriate label (`enhancement`, `bug`, `breaking`, `dependencies`, `ci`) - [ ] ready for review
82 lines
2.6 KiB
Go
82 lines
2.6 KiB
Go
package identity
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
"github.com/pomerium/pomerium/pkg/identity/identity"
|
|
)
|
|
|
|
// MockProvider provides a mocked implementation of the providers interface.
|
|
type MockProvider struct {
|
|
AuthenticateResponse oauth2.Token
|
|
AuthenticateError error
|
|
RefreshResponse oauth2.Token
|
|
RefreshError error
|
|
RevokeError error
|
|
UpdateUserInfoError error
|
|
SignInError error
|
|
SignOutError error
|
|
DeviceAuthResponse oauth2.DeviceAuthResponse
|
|
DeviceAuthError error
|
|
DeviceAccessTokenResponse oauth2.Token
|
|
DeviceAccessTokenError error
|
|
}
|
|
|
|
// Authenticate is a mocked providers function.
|
|
func (mp MockProvider) Authenticate(context.Context, string, identity.State) (*oauth2.Token, error) {
|
|
return &mp.AuthenticateResponse, mp.AuthenticateError
|
|
}
|
|
|
|
// Refresh is a mocked providers function.
|
|
func (mp MockProvider) Refresh(context.Context, *oauth2.Token, identity.State) (*oauth2.Token, error) {
|
|
return &mp.RefreshResponse, mp.RefreshError
|
|
}
|
|
|
|
// Revoke is a mocked providers function.
|
|
func (mp MockProvider) Revoke(_ context.Context, _ *oauth2.Token) error {
|
|
return mp.RevokeError
|
|
}
|
|
|
|
// UpdateUserInfo is a mocked providers function.
|
|
func (mp MockProvider) UpdateUserInfo(_ context.Context, _ *oauth2.Token, _ any) error {
|
|
return mp.UpdateUserInfoError
|
|
}
|
|
|
|
// Name returns the provider name.
|
|
func (mp MockProvider) Name() string {
|
|
return "mock"
|
|
}
|
|
|
|
// SignOut is a mocked providers function.
|
|
func (mp MockProvider) SignOut(_ http.ResponseWriter, _ *http.Request, _, _, _ string) error {
|
|
return mp.SignOutError
|
|
}
|
|
|
|
// SignIn is a mocked providers function.
|
|
func (mp MockProvider) SignIn(_ http.ResponseWriter, _ *http.Request, _ string) error {
|
|
return mp.SignInError
|
|
}
|
|
|
|
// DeviceAuth implements Authenticator.
|
|
func (mp MockProvider) DeviceAuth(_ context.Context) (*oauth2.DeviceAuthResponse, error) {
|
|
return &mp.DeviceAuthResponse, mp.DeviceAuthError
|
|
}
|
|
|
|
// DeviceAccessToken implements Authenticator.
|
|
func (mp MockProvider) DeviceAccessToken(_ context.Context, _ *oauth2.DeviceAuthResponse, _ identity.State) (*oauth2.Token, error) {
|
|
return &mp.DeviceAccessTokenResponse, mp.DeviceAccessTokenError
|
|
}
|
|
|
|
// VerifyAccessToken verifies an access token.
|
|
func (mp MockProvider) VerifyAccessToken(_ context.Context, _ string) (claims map[string]any, err error) {
|
|
return nil, fmt.Errorf("VerifyAccessToken not implemented")
|
|
}
|
|
|
|
// VerifyIdentityToken verifies an identity token.
|
|
func (mp MockProvider) VerifyIdentityToken(_ context.Context, _ string) (claims map[string]any, err error) {
|
|
return nil, fmt.Errorf("VerifyIdentityToken not implemented")
|
|
}
|