oidctest
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Index¶
- func FakeIDPKey() (*rsa.PrivateKey, error)
- func OAuth2GetCode(rawAuthURL string, doRequest func(req *http.Request) (*http.Response, error)) (string, error)
- func StatusError(code int, err error) error
- func With429(params With429Arguments) func(*FakeIDP)
- func WithAccessTokenJWTHook(hook func(email string, exp time.Time) jwt.MapClaims) func(*FakeIDP)
- func WithAuthorizedRedirectURL(hook func(redirectURL string) error) func(*FakeIDP)
- func WithCallbackPath(path string) func(*FakeIDP)
- func WithCustomClientAuth(hook func(t testing.TB, req *http.Request) (url.Values, error)) func(*FakeIDP)
- func WithDefaultExpire(d time.Duration) func(*FakeIDP)
- func WithDefaultIDClaims(claims jwt.MapClaims) func(*FakeIDP)
- func WithDynamicUserInfo(userInfoFunc func(email string) (jwt.MapClaims, error)) func(*FakeIDP)
- func WithHookWellKnown(hook func(r *http.Request, j *ProviderJSON) error) func(*FakeIDP)
- func WithIssuer(issuer string) func(*FakeIDP)
- func WithLogger(logger slog.Logger) func(*FakeIDP)
- func WithLogging(t testing.TB, options *slogtest.Options) func(*FakeIDP)
- func WithMiddlewares(mws ...func(http.Handler) http.Handler) func(*FakeIDP)
- func WithMutateToken(mutateToken func(token map[string]interface{})) func(*FakeIDP)
- func WithRefresh(hook func(email string) error) func(*FakeIDP)
- func WithServing() func(*FakeIDP)
- func WithStaticCredentials(id, secret string) func(*FakeIDP)
- func WithStaticUserInfo(info jwt.MapClaims) func(*FakeIDP)
- type ExternalAuthConfigOptions
- type FakeIDP
- func (f *FakeIDP) AppCredentials() (clientID string, clientSecret string)
- func (f *FakeIDP) AttemptLogin(t testing.TB, client *codersdk.Client, idTokenClaims jwt.MapClaims, ...) (*codersdk.Client, *http.Response)
- func (f *FakeIDP) CreateAuthCode(t testing.TB, state string) string
- func (*FakeIDP) DeviceLogin(t testing.TB, client *codersdk.Client, externalAuthID string)
- func (f *FakeIDP) ExternalAuthConfig(t testing.TB, id string, custom *ExternalAuthConfigOptions, ...) *externalauth.Config
- func (f *FakeIDP) ExternalLogin(t testing.TB, client *codersdk.Client, opts ...func(r *http.Request))
- func (f *FakeIDP) GenerateAuthenticatedToken(claims jwt.MapClaims) (*oauth2.Token, error)
- func (f *FakeIDP) HTTPClient(rest *http.Client) *http.Client
- func (f *FakeIDP) IssuerURL() *url.URL
- func (f *FakeIDP) Login(t testing.TB, client *codersdk.Client, idTokenClaims jwt.MapClaims, ...) (*codersdk.Client, *http.Response)
- func (f *FakeIDP) LoginWithClient(t testing.TB, client *codersdk.Client, idTokenClaims jwt.MapClaims, ...) (*codersdk.Client, *http.Response)
- func (f *FakeIDP) OIDCCallback(t testing.TB, state string, idTokenClaims jwt.MapClaims) *http.Response
- func (f *FakeIDP) OIDCConfig(t testing.TB, scopes []string, opts ...func(cfg *coderd.OIDCConfig)) *coderd.OIDCConfig
- func (f *FakeIDP) OIDCConfigSkipIssuerChecks(t testing.TB, scopes []string, opts ...func(cfg *coderd.OIDCConfig)) *coderd.OIDCConfig
- func (f *FakeIDP) OauthConfig(t testing.TB, scopes []string) *oauth2.Config
- func (f *FakeIDP) PublicKey() crypto.PublicKey
- func (f *FakeIDP) RefreshUsed(refreshToken string) bool
- func (f *FakeIDP) SetCoderdCallback(callback func(req *http.Request) (*http.Response, error))
- func (f *FakeIDP) SetCoderdCallbackHandler(handler http.HandlerFunc)
- func (f *FakeIDP) SetRedirect(t testing.TB, u string)
- func (f *FakeIDP) UpdateRefreshClaims(refreshToken string, claims jwt.MapClaims)
- func (f *FakeIDP) WellknownConfig() ProviderJSON
- type FakeIDPOpt
- type LoginHelper
- func (h *LoginHelper) AttemptLogin(t *testing.T, idTokenClaims jwt.MapClaims) (*codersdk.Client, *http.Response)
- func (*LoginHelper) ExpireOauthToken(t *testing.T, db database.Store, user *codersdk.Client) database.UserLink
- func (h *LoginHelper) ForceRefresh(t *testing.T, db database.Store, user *codersdk.Client, idToken jwt.MapClaims)
- func (h *LoginHelper) Login(t *testing.T, idTokenClaims jwt.MapClaims) (*codersdk.Client, *http.Response)
- type ProviderJSON
- type With429Arguments
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcFakeIDPKey¶added inv2.20.0
func FakeIDPKey() (*rsa.PrivateKey,error)
funcOAuth2GetCode¶added inv2.9.0
func OAuth2GetCode(rawAuthURLstring, doRequest func(req *http.Request) (*http.Response,error)) (string,error)
OAuth2GetCode emulates a user clicking "allow" on the IDP page. When doingunit tests, it's easier to skip this step sometimes. It does make an actualrequest to the IDP, so it should be equivalent to doing this "manually" withactual requests.
funcStatusError¶added inv2.1.5
funcWith429¶added inv2.9.0
func With429(paramsWith429Arguments) func(*FakeIDP)
With429 will emulate a 429 response for the selected paths.
funcWithAccessTokenJWTHook¶added inv2.20.0
funcWithCallbackPath¶added inv2.8.0
funcWithDefaultExpire¶added inv2.7.0
funcWithDefaultIDClaims¶added inv2.7.0
func WithDefaultIDClaims(claims jwt.MapClaims) func(*FakeIDP)
funcWithHookWellKnown¶added inv2.14.0
func WithHookWellKnown(hook func(r *http.Request, j *ProviderJSON)error) func(*FakeIDP)
funcWithIssuer¶
funcWithLogger¶added inv2.7.0
funcWithLogging¶
WithLogging is optional, but will log some HTTP calls made to the IDP.
funcWithMiddlewares¶added inv2.7.0
funcWithMutateToken¶added inv2.3.0
WithExtra returns extra fields that be accessed on the returned Oauth Token.These extra fields can override the default fields (id_token, access_token, etc).
funcWithRefresh¶added inv2.1.5
WithRefresh is called when a refresh token is used. The email isthe email of the user that is being refreshed assuming the claims are correct.
funcWithServing¶
func WithServing() func(*FakeIDP)
WithServing makes the IDP run an actual http server.
funcWithStaticCredentials¶added inv2.7.0
funcWithStaticUserInfo¶
func WithStaticUserInfo(info jwt.MapClaims) func(*FakeIDP)
WithStaticUserInfo is optional, but will return the same user info forevery user on the /userinfo endpoint.
Types¶
typeExternalAuthConfigOptions¶added inv2.5.0
type ExternalAuthConfigOptions struct {// ValidatePayload is the payload that is used when the user calls the// equivalent of "userinfo" for oauth2. This is not standardized, so is// different for each provider type.//// The int,error payload can control the response if set.ValidatePayload func(emailstring) (interface{},int,error)UseDeviceAuthbool// contains filtered or unexported fields}
ExternalAuthConfigOptions exists to provide additional functionality ontopof the standard "validate" url. Some providers like github we actually parsethe response from the validate URL to gain additional information.
func (*ExternalAuthConfigOptions)AddRoute¶added inv2.5.0
func (o *ExternalAuthConfigOptions) AddRoute(routestring, handle func(emailstring, rwhttp.ResponseWriter, r *http.Request)) *ExternalAuthConfigOptions
typeFakeIDP¶
type FakeIDP struct {// contains filtered or unexported fields}
FakeIDP is a functional OIDC provider.It only supports 1 OIDC client.
funcNewFakeIDP¶
func NewFakeIDP(ttesting.TB, opts ...FakeIDPOpt) *FakeIDP
func (*FakeIDP)AppCredentials¶added inv2.7.0
func (*FakeIDP)AttemptLogin¶
func (*FakeIDP)CreateAuthCode¶added inv2.7.0
CreateAuthCode emulates a user clicking "allow" on the IDP page. When doingunit tests, it's easier to skip this step sometimes. It does make an actualrequest to the IDP, so it should be equivalent to doing this "manually" withactual requests.
func (*FakeIDP)DeviceLogin¶added inv2.8.0
DeviceLogin does the oauth2 device flow for external auth providers.
func (*FakeIDP)ExternalAuthConfig¶added inv2.5.0
func (f *FakeIDP) ExternalAuthConfig(ttesting.TB, idstring, custom *ExternalAuthConfigOptions, opts ...func(cfg *externalauth.Config)) *externalauth.Config
ExternalAuthConfig is the config for external auth providers.
func (*FakeIDP)ExternalLogin¶added inv2.5.0
func (f *FakeIDP) ExternalLogin(ttesting.TB, client *codersdk.Client, opts ...func(r *http.Request))
ExternalLogin does the oauth2 flow for external auth providers. This requiresan authenticated coder client.
func (*FakeIDP)GenerateAuthenticatedToken¶added inv2.1.5
GenerateAuthenticatedToken skips all oauth2 flows, and just generates avalid token for some given claims.
func (*FakeIDP)HTTPClient¶
HTTPClient does nothing if IsServing is used.
If IsServing is not used, then it will return a client that will make requeststo the IDP all in memory. If a request is not to the IDP, then the passed inclient will be used. If no client is passed in, then any regular networkrequests will fail.
func (*FakeIDP)Login¶
func (f *FakeIDP) Login(ttesting.TB, client *codersdk.Client, idTokenClaims jwt.MapClaims, opts ...func(r *http.Request)) (*codersdk.Client, *http.Response)
Login does the full OIDC flow starting at the "LoginButton".The client argument is just to get the URL of the Coder instance.
The client passed in is just to get the url of the Coder instance.The actual client that is used is 100% unauthenticated and fresh.
func (*FakeIDP)LoginWithClient¶
func (f *FakeIDP) LoginWithClient(ttesting.TB, client *codersdk.Client, idTokenClaims jwt.MapClaims, opts ...func(r *http.Request)) (*codersdk.Client, *http.Response)
LoginWithClient reuses the context of the passed in client. This means the samecookies will be used. This should be an unauthenticated client in most cases.
This is a niche case, but it is needed for testing ConvertLoginType.
func (*FakeIDP)OIDCCallback¶
func (f *FakeIDP) OIDCCallback(ttesting.TB, statestring, idTokenClaims jwt.MapClaims) *http.Response
OIDCCallback will emulate the IDP redirecting back to the Coder callback.This is helpful if no Coderd exists because the IDP needs to redirect tosomething.Essentially this is used to fake the Coderd side of the exchange.The flow starts at the user hitting the OIDC login page.
func (*FakeIDP)OIDCConfig¶
func (f *FakeIDP) OIDCConfig(ttesting.TB, scopes []string, opts ...func(cfg *coderd.OIDCConfig)) *coderd.OIDCConfig
func (*FakeIDP)OIDCConfigSkipIssuerChecks¶added inv2.14.0
func (f *FakeIDP) OIDCConfigSkipIssuerChecks(ttesting.TB, scopes []string, opts ...func(cfg *coderd.OIDCConfig)) *coderd.OIDCConfig
func (*FakeIDP)OauthConfig¶added inv2.14.0
func (*FakeIDP)RefreshUsed¶
RefreshUsed returns if the refresh token has been used. All refresh tokenscan only be used once, then they are deleted.
func (*FakeIDP)SetCoderdCallback¶
SetCoderdCallback is optional and only works if not using the IsServing.It will setup a fake "Coderd" for the IDP to call when the IDP redirectsback after authenticating.
func (*FakeIDP)SetCoderdCallbackHandler¶
func (f *FakeIDP) SetCoderdCallbackHandler(handlerhttp.HandlerFunc)
func (*FakeIDP)SetRedirect¶
SetRedirect is required for the IDP to know where to redirect and callCoderd.
func (*FakeIDP)UpdateRefreshClaims¶
UpdateRefreshClaims allows the caller to change what claims are returnedfor a given refresh token. By default, all refreshes use the same claims asthe original IDToken issuance.
func (*FakeIDP)WellknownConfig¶added inv2.1.5
func (f *FakeIDP) WellknownConfig()ProviderJSON
typeFakeIDPOpt¶
type FakeIDPOpt func(idp *FakeIDP)
typeLoginHelper¶
type LoginHelper struct {// contains filtered or unexported fields}
LoginHelper helps with logging in a user and refreshing their oauth tokens.It is mainly because refreshing oauth tokens is a bit tricky and requiressome database manipulation.
funcNewLoginHelper¶
func NewLoginHelper(client *codersdk.Client, fake *FakeIDP) *LoginHelper
func (*LoginHelper)AttemptLogin¶added inv2.5.0
func (h *LoginHelper) AttemptLogin(t *testing.T, idTokenClaims jwt.MapClaims) (*codersdk.Client, *http.Response)
AttemptLogin does not assert a successful login.
func (*LoginHelper)ExpireOauthToken¶
func (*LoginHelper) ExpireOauthToken(t *testing.T, dbdatabase.Store, user *codersdk.Client)database.UserLink
ExpireOauthToken expires the oauth token for the given user.
func (*LoginHelper)ForceRefresh¶
func (h *LoginHelper) ForceRefresh(t *testing.T, dbdatabase.Store, user *codersdk.Client, idToken jwt.MapClaims)
ForceRefresh forces the client to refresh its oauth token. It does this byexpiring the oauth token, then doing an authenticated call. This will forcethe API Key middleware to refresh the oauth token.
A unit test assertion makes sure the refresh token is used.
typeProviderJSON¶added inv2.1.5
type ProviderJSON struct {Issuerstring `json:"issuer"`AuthURLstring `json:"authorization_endpoint"`TokenURLstring `json:"token_endpoint"`JWKSURLstring `json:"jwks_uri"`UserInfoURLstring `json:"userinfo_endpoint"`DeviceCodeURLstring `json:"device_authorization_endpoint"`Algorithms []string `json:"id_token_signing_alg_values_supported"`// This is customExternalAuthURLstring `json:"external_auth_url"`}
ProviderJSON is the .well-known/configuration JSON