
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
github.com/zymsys/gokta
Note: This library is currently in an alpha stage. It's under active development and may be subject to changes. While Gokta is functional, it's recommended for testing and development purposes at this stage. Please use caution when integrating it into production environments.
Welcome to Gokta, a specialized library for integrating Okta authentication in Go web applications. Gokta simplifies the process of implementing OAuth 2.0 workflows, handling token management, user sessions, and secure user authentication against Okta's Identity Cloud services in web-based Go applications.
As of now, Gokta is focused on supporting the "Web Application" type in Okta's suite of application offerings. This library provides a streamlined approach to OAuth 2.0 authentication, ensuring a seamless and secure user experience. Features like JWT token parsing, configurable logging, and session management are all part of Gokta, crafted to make the integration of Okta authentication straightforward and efficient.
Looking ahead, I aim to expand Gokta's capabilities to include support for Single-Page Applications.
To use Gokta, ensure that your environment meets the following requirements:
Please make sure these requirements are met before integrating Gokta into your application.
To install Gokta in your Go project, follow these steps:
import "github.com/zymsys/gokta"
go get github.com/zymsys/gokta
This command downloads the Gokta package along with its dependencies and updates your go.mod file.go mod tidy
This will install Gokta and make it available in your Go project. Next, you can proceed to configure Gokta as per your project's requirements.To configure Gokta in your Go project, follow these steps:
package main
import (
"github.com/zymsys/gokta"
"github.com/zymsys/gokta/config"
)
func main() {
cfg := config.Config{
ClientID: "YOUR_OKTA_CLIENT_ID",
ClientSecret: "YOUR_OKTA_CLIENT_SECRET",
Issuer: "YOUR_OKTA_ISSUER_URL",
RedirectURI: "YOUR_APPLICATION_REDIRECT_URI",
SessionKey: "YOUR_SESSION_ENCRYPTION_KEY",
LoggedInURI: "URI_AFTER_SUCCESSFUL_LOGIN",
PostLogoutRedirectURI: "URI_AFTER_LOGOUT",
}
// Initialize Gokta with the configuration
oktaClient := gokta.New(cfg)
// Further setup and usage of oktaClient
}
cfg.Logger = MyCustomLogger{}
cfg.HttpClient = &http.Client{Timeout: time.Second * 30}
After configuring Gokta, you can integrate it into your application's authentication flow.
After configuring Gokta as described in the Configuration section, you can integrate it into your application's authentication flow. Here are some examples and explanations on how to use Gokta:
http.Handle("/protected-route", oktaClient.Middleware()(yourProtectedHandler))
err := oktaClient.RegisterCallbackRoute(func(path string, handler http.Handler) {
// Example of registering the route with your HTTP library
http.Handle(path, handler)
})
if err != nil {
log.Fatalf("Error registering callback route: %v", err)
}
http.HandleFunc("/logout", oktaClient.LogoutHandler)
claims, err := oktaClient.GetUserClaims(request)
if err != nil {
// Handle error
}
userEmail := claims["email"].(string)
fmt.Println("User email:", userEmail)
{
"email": "example@email.com",
"name": "John Doe",
"preferred_username": "example@email.com",
"sub": "00u1m8kb1ssZc65355d7"
}
To use this handler:
http.HandleFunc("/userinfo", oktaClient.UserClaimsHandler)
The examples above provide a basic overview of integrating and using Gokta in your Go web applications. For more advanced usage, refer to the detailed documentation within the code.This section provides a brief overview of the key types and functions available in the Gokta library:
OAuthClient:
This reference is a concise guide to the primary interfaces of Gokta. For more detailed information, including parameters and return types, refer to the documentation within the codebase.
Gokta offers flexible logging capabilities, enabling the use of built-in loggers or the implementation of custom logging solutions. Here's how to use these features effectively:
Gokta includes two predefined loggers:
To utilize one of these loggers, set it in your configuration:
import (
"github.com/zymsys/gokta/config"
"github.com/zymsys/gokta/logging"
)
cfg := config.Config{
// ... other configuration fields ...
Logger: logging.StandardLogger{},
}
This will enable Gokta to use StandardLogger for all logging activities.
For customized logging, you can implement the Logger interface, which includes four methods: Debug, Info, Warn, and Error. These methods accept a variadic interface{} argument, providing flexibility in message formatting.
To create a custom logger:
Here's a snippet showing how to set your custom logger in the configuration:
cfg := config.Config{
// ... other configuration fields ...
Logger: MyCustomLogger{}, // Replace with your custom logger
}
By following the approach used in the default loggers, you can create a logger that aligns seamlessly with your application's logging strategy.
Gokta is designed to handle errors gracefully, ensuring that your application remains robust and reliable. Here's an overview of the error handling approach in Gokta:
Gokta returns detailed error information in many cases, particularly during token exchange and authentication processes. Common error responses include:
When using Gokta, you should handle errors at the points where they are likely to occur. This includes:
Contributions to Gokta are warmly welcomed and greatly appreciated. Whether it's bug fixes, feature enhancements, or documentation improvements, here's how you can contribute:
By following these steps, you can contribute to the ongoing development and improvement of Gokta. We look forward to seeing your contributions!
Gokta is licensed under the Apache License 2.0. The full license text is included in the LICENSE file of this repository.
If you have any questions, need support, or want to discuss Gokta, please feel free to open an issue on our GitHub repository.
Before creating a new issue, we recommend checking existing issues to see if your question or problem has already been addressed. If you find a related issue, feel free to add additional comments or insights.
For general discussions or questions, opening a new issue with a clear description will ensure that we can engage and provide assistance.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.