Senior
Did you have Keycloak for authentication or your own solution?
sobes.tech AI
Answer from AI
For authentication, ready-made solutions like Keycloak are often used, especially if support for OAuth2, OpenID Connect standards, and centralized user management is needed. Keycloak allows for quick implementation of authentication and authorization with minimal effort.
If the requirements were specific or the infrastructure did not allow the use of third-party services, a custom solution could be implemented. In such cases, an authorization service with JWT tokens, session management, and roles is usually built.
An example of using Keycloak with a Go application — JWT token validation:
import (
"github.com/coreos/go-oidc"
"golang.org/x/net/context"
"net/http"
)
func authMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("Authorization")
// Token validation via Keycloak
// ...
next.ServeHTTP(w, r)
})
}
Thus, the choice depends on the project requirements and infrastructure.