Movatterモバイル変換


[0]ホーム

URL:


oauth2providertest

package
v2.26.0Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2025 License:AGPL-3.0Imports:15Imported by:0

Details

Repository

github.com/coder/coder

Links

Documentation

Overview

Package oauth2providertest provides comprehensive testing utilities for OAuth2 identity provider functionality.It includes helpers for creating OAuth2 apps, performing authorization flows, token exchanges,PKCE challenge generation and verification, and testing error scenarios.

Index

Constants

View Source
const (// TestRedirectURI is the standard test redirect URITestRedirectURI = "http://localhost:9876/callback"// TestResourceURI is used for testing resource parameterTestResourceURI = "https://api.example.com"// Invalid PKCE verifier for negative testingInvalidCodeVerifier = "wrong-verifier")

Test constants for OAuth2 testing

Variables

View Source
var OAuth2ErrorTypes = struct {InvalidRequeststringInvalidClientstringInvalidGrantstringUnauthorizedClientstringUnsupportedGrantTypestringInvalidScopestring}{InvalidRequest:       "invalid_request",InvalidClient:        "invalid_client",InvalidGrant:         "invalid_grant",UnauthorizedClient:   "unauthorized_client",UnsupportedGrantType: "unsupported_grant_type",InvalidScope:         "invalid_scope",}

OAuth2ErrorTypes contains standard OAuth2 error codes

Functions

funcAuthorizeOAuth2App

func AuthorizeOAuth2App(t *testing.T, client *codersdk.Client, baseURLstring, paramsAuthorizeParams)string

AuthorizeOAuth2App performs the OAuth2 authorization flow and returns the authorization code

funcCleanupOAuth2App

func CleanupOAuth2App(t *testing.T, client *codersdk.Client, appIDuuid.UUID)

CleanupOAuth2App deletes an OAuth2 app (helper for test cleanup)

funcCreateTestOAuth2App

func CreateTestOAuth2App(t *testing.T, client *codersdk.Client) (*codersdk.OAuth2ProviderApp,string)

CreateTestOAuth2App creates an OAuth2 app for testing and returns the app and client secret

funcExchangeCodeForToken

func ExchangeCodeForToken(t *testing.T, baseURLstring, paramsTokenExchangeParams) *oauth2.Token

ExchangeCodeForToken exchanges an authorization code for tokens

funcFetchOAuth2Metadata

func FetchOAuth2Metadata(t *testing.T, baseURLstring) map[string]any

FetchOAuth2Metadata fetches and returns OAuth2 authorization server metadata

funcGenerateCodeChallenge

func GenerateCodeChallenge(verifierstring)string

GenerateCodeChallenge creates an S256 code challenge from a verifier

funcGeneratePKCE

func GeneratePKCE(t *testing.T) (verifier, challengestring)

GeneratePKCE generates a random PKCE code verifier and challenge

funcGenerateState

func GenerateState(t *testing.T)string

GenerateState generates a random state parameter

funcPerformTokenExchangeExpectingError

func PerformTokenExchangeExpectingError(t *testing.T, baseURLstring, paramsTokenExchangeParams, expectedErrorstring)

PerformTokenExchangeExpectingError performs a token exchange expecting an OAuth2 error

funcRequireOAuth2Error

func RequireOAuth2Error(t *testing.T, resp *http.Response, expectedErrorstring)

RequireOAuth2Error checks that the HTTP response contains an expected OAuth2 error

Types

typeAuthorizeParams

type AuthorizeParams struct {ClientIDstringResponseTypestringRedirectURIstringStatestringCodeChallengestringCodeChallengeMethodstringResourcestringScopestring}

AuthorizeParams contains parameters for OAuth2 authorization

typeOAuth2Error

type OAuth2Error struct {Errorstring `json:"error"`ErrorDescriptionstring `json:"error_description,omitempty"`}

OAuth2Error represents an OAuth2 error response

typeTokenExchangeParams

type TokenExchangeParams struct {GrantTypestringCodestringClientIDstringClientSecretstringCodeVerifierstringRedirectURIstringRefreshTokenstringResourcestring}

TokenExchangeParams contains parameters for token exchange

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp