Note
The implemenation only has been tested with the Authentik Auth provider. More information can be found here
An auth OIDC-based implemenation for SOARCA based using the GIN framework. Library provides convient functionality and middleware for the OIDCS token validation and redirects.
Gauth uses encrypted stored cookies for storing the jwt-token client-side. For more information on secure cookies we refer to Gorilla. By default the life time of a stored session cookie is set to 8 hours, see COOKIE_LIFETIME
under /cookies/cookie.go
.
The library can be used in two modes:
OIDC Redirect mode
: Provides the redirect functionality for the OICS flowToken validation mode
: Provides a middleware for token validation
In the examples section below more information is provided.
First, install the GAuth package:
go get github.com/COSSAS/gauth
For OIDC authentication:
OIDC_ISSUER
: OIDC provider URLOIDC_CLIENT_ID
: Application client IDOIDC_CLIENT_SECRET
: Application client secret (for redirect mode)
OIDC_REDIRECT_URL
: "http://localhost:8081/auth/soarca_gui/callback"COOKIE_SECRET_KEY
: "SOME_COOKIE_SECRET" #openssl rand -base64 32 or head -c 32 /dev/urandom | base64 # OPTIONALOIDC_SKIP_TLS_VERIFY
: Set totrue
for development (not recommended for production)
gauth.OIDCRedirectToLogin(c *gin.Context)
: redirect unauthenticated users to OIDC logingauth.OIDCCallBack(c *gin.Context, "/dashboard")
: handle OIDC provider callback after authenticationgauth.Logout(c *gin.Context, "/login")
: logout route to clear session and redirect
gauth.LoadAuthContext()
: Attempts to authenticate the user via session cookie or bearer token
gauth.Middleware([]string)
:
- Ensures the user is authenticated
- Optional group-based authorization
- Passes if no groups are specified
- Requires user to be in ALL specified groups
Examples are located in the /examples/
directory. Real life implementation can be found here:
examples/basic/main.go
: Demonstrates OIDC authentication configuration using:- Default configuration
- Login and callback routes
- Protected routes with middleware
- Logout functionality
examples/validation/main.go
: Demonstrates the validation proces of token obtained through a jwt-tokenbearer
, and validated against the OIDC provider.
- Always use
HTTPS
in production - Set
OIDC_SKIP_TLS_VERIFY
to false - Manage environment variables securely
- Currently JWT-tokens are stored encrypted on the client-side.