@@ -294,6 +294,135 @@ html, err := scalargo.NewV2(
294294)
295295```
296296
297+ ### 🔐 ** Authentication Configuration**
298+
299+ Scalar-Go provides comprehensive authentication support for modern APIs, including API Keys, HTTP Basic/Bearer, and OAuth2 flows.
300+
301+ #### ** Enhanced API Key Authentication**
302+
303+ ``` go
304+ // Simple API Key (header-based, backward compatible)
305+ scalargo.WithAuthenticationOpts (
306+ scalargo.WithAPIKey (" your-api-key" ),
307+ )
308+
309+ // Custom header name
310+ scalargo.WithAuthenticationOpts (
311+ scalargo.WithAPIKey (" your-api-key" , scalargo.WithAPIKeyName (" X-API-Key" )),
312+ )
313+
314+ // Query parameter-based API Key
315+ scalargo.WithAuthenticationOpts (
316+ scalargo.WithAPIKeyQuery (" api_key" , " your-api-key" ),
317+ )
318+
319+ // Cookie-based API Key
320+ scalargo.WithAuthenticationOpts (
321+ scalargo.WithAPIKeyCookie (" session_token" , " your-token" ),
322+ )
323+ ```
324+
325+ #### ** HTTP Basic & Bearer Authentication**
326+
327+ ``` go
328+ // HTTP Basic Auth
329+ scalargo.WithAuthenticationOpts (
330+ scalargo.WithHTTPBasicAuth (" username" , " password" ),
331+ )
332+
333+ // HTTP Bearer Token
334+ scalargo.WithAuthenticationOpts (
335+ scalargo.WithHTTPBearerToken (" your-bearer-token" ),
336+ )
337+ ```
338+
339+ #### ** OAuth2 Authentication**
340+
341+ Full OAuth2 support with all standard flows and PKCE.
342+
343+ ** Authorization Code Flow (Recommended)**
344+ ``` go
345+ scalargo.WithAuthenticationOpts (
346+ scalargo.WithOAuth2AuthorizationCode (
347+ " https://auth.example.com/oauth/authorize" ,
348+ " https://auth.example.com/oauth/token" ,
349+ scalargo.WithOAuth2ClientID (" my-client-id" ),
350+ scalargo.WithOAuth2RedirectURI (" https://myapp.com/callback" ),
351+ scalargo.WithOAuth2PKCE (scalargo.PKCES256 ), // SHA-256 PKCE (recommended)
352+ scalargo.WithOAuth2Scopes (" read:api" , " write:api" ),
353+ ),
354+ )
355+ ```
356+
357+ ** Client Credentials Flow**
358+ ``` go
359+ scalargo.WithAuthenticationOpts (
360+ scalargo.WithOAuth2ClientCredentials (
361+ " https://auth.example.com/oauth/token" ,
362+ scalargo.WithOAuth2ClientID (" service-account" ),
363+ scalargo.WithOAuth2ClientSecret (" super-secret" ),
364+ ),
365+ )
366+ ```
367+
368+ ** Advanced OAuth2 Customization**
369+ ``` go
370+ scalargo.WithAuthenticationOpts (
371+ scalargo.WithOAuth2AuthorizationCode (
372+ " https://auth.example.com/oauth/authorize" ,
373+ " https://auth.example.com/oauth/token" ,
374+ scalargo.WithOAuth2ClientID (" my-client" ),
375+ scalargo.WithOAuth2CustomToken (" custom_access_token" ), // Custom token field name
376+ scalargo.WithOAuth2AdditionalAuthParams (map [string ]string {
377+ " audience" : " https://api.example.com" ,
378+ }),
379+ scalargo.WithOAuth2AdditionalTokenParams (map [string ]string {
380+ " resource" : " https://resource.example.com" ,
381+ }),
382+ scalargo.WithOAuth2CredentialsLocation (scalargo.OAuth2CredentialsHeader ),
383+ ),
384+ )
385+ ```
386+
387+ #### ** Multiple Security Schemes**
388+
389+ Configure multiple authentication methods for your API:
390+
391+ ``` go
392+ scalargo.WithAuthenticationOpts (
393+ // Define multiple security schemes
394+ scalargo.WithSecurityScheme (" api_key" ,
395+ scalargo.APIKeyScheme (" X-API-Key" , scalargo.APIKeyLocationHeader , " default-key" ),
396+ ),
397+ scalargo.WithSecurityScheme (" bearer_auth" ,
398+ scalargo.BearerScheme (" default-token" ),
399+ ),
400+ scalargo.WithSecurityScheme (" oauth2" ,
401+ scalargo.OAuth2Scheme (
402+ scalargo.OAuth2FlowAuthorizationCode ,
403+ scalargo.OAuth2Config {
404+ AuthorizationURL : " https://auth.example.com/authorize" ,
405+ TokenURL : " https://auth.example.com/token" ,
406+ ClientID : " my-client" ,
407+ UsePKCE : scalargo.PKCES256 ,
408+ SelectedScopes : []string {" read:api" , " write:api" },
409+ },
410+ ),
411+ ),
412+ // Set preferred security scheme
413+ scalargo.WithPreferredSecurityScheme (" bearer_auth" ),
414+ )
415+ ```
416+
417+ ** PKCE Modes:**
418+ - ` scalargo.PKCES256 ` - SHA-256 PKCE (recommended for production)
419+ - ` scalargo.PKCEPlain ` - Plain PKCE
420+ - ` scalargo.PKCEDisabled ` - Disable PKCE
421+
422+ ** OAuth2 Credentials Location:**
423+ - ` scalargo.OAuth2CredentialsHeader ` - Send credentials in Authorization header (default)
424+ - ` scalargo.OAuth2CredentialsBody ` - Send credentials in request body
425+
297426## 🚀 Real-World Examples
298427
299428### 🏢 ** Enterprise API Documentation**
0 commit comments