Skip to content

Latest commit

 

History

History
90 lines (79 loc) · 1.84 KB

USAGE.md

File metadata and controls

90 lines (79 loc) · 1.84 KB

Keycloak GOLANG Plugin Usage

This is a GOLANG application plugin deigned to work with keycloak for authentication

Adding a Client

To create a connection with your keycloak client you will need add the 'Keycloak OIDC JSON' file to <$AppHomeDir>/json/ folder.
This file can be found in the Keycloak Console in Clients → <$ClientName> → Installation

Methods

Init

Init will create the connection between the keycloak client and your application
Params:

Init(keycloakserver string, server string)

Calling:

server = "http://" + <$AppHost> + ":" + <$AppPort>
keycloakserver = "http://" + <$KeycloakHost> + ":" + <$KeycloakPort>

keycloak.Init(keycloakserver, server)

Login

Login and LoginCallback will direct the user the login screen and verify their login token
Params:

HandleLogin(w http.ResponseWriter, r *http.Request)
HandleLoginCallback(w http.ResponseWriter, r *http.Request)

Calling:

//Login User
//Unauthenticated
Route{
	"handleLogin",
	"GET",
	"/login",
	keycloak.HandleLogin,
},
//Login helper
//Authenticated
Route{
	"handleLoginCallback",
	"GET",
	"/loginCallback",
	keycloak.HandleLoginCallback,
},

MiddleWare

Middleware provides a means to have users authenticated before accessing a page
Params:

AuthMiddleware(next http.HandlerFunc) http.HandlerFunc 

Calling:

//Example Function Redirect
//Authenticated
//indexHandler is an http.HandlerFunc
Route{
	"Index",
	"GET",
	"/",
	keycloak.AuthMiddleware(indexHandler),
},

Logout

Middleware provides a means to have users authenticated before accessing a page
Params:

Logout(w http.ResponseWriter, r *http.Request)

Calling:

//Logout, redirects to login
///Unauthenticatec
Route{
	"logout",
	"GET",
	"/logout",
	keycloak.Logout,
},