client library for helseid
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-14 09:20:29 +02:00
test create unique client assertion for every call to comply with new rules 2026-07-07 13:56:05 +02:00
go.mod update module path 2026-05-22 10:05:25 +02:00
go.sum add refresh token 2026-05-15 10:58:09 +02:00
helseid.go rename func 2026-07-08 16:15:59 +02:00
helseid_endsession.go add endsession func 2026-07-13 12:45:06 +02:00
helseid_keygen.go temp commit 2026-07-08 14:27:42 +02:00
helseid_oid.go add cookiestorage and make initialize cleaner 2026-07-06 16:15:59 +02:00
helseid_par.go update tests 2026-07-08 16:14:09 +02:00
helseid_test.go create first branch 2026-07-13 12:26:35 +02:00
helseid_token.go update tests 2026-07-08 16:14:09 +02:00
helseid_userinfo.go add userinfo support 2026-05-15 13:08:36 +02:00
helseid_validator.go temp commit 2026-07-08 14:27:42 +02:00
http_handlers.go rename func 2026-07-08 16:15:59 +02:00
http_middleware.go add missing return 2026-07-14 09:20:29 +02:00
http_utils.go remove cookie params 2026-07-13 13:21:45 +02:00
readme.md add endsession func 2026-07-13 12:45:06 +02:00

Initialize struct with options

helseid, err := helseid.NewHelseID(&Options{
	Config: Config{
		BaseUrl:     "https://helseid-sts.test.nhn.no",
		ApiScopes:    []string{"wch:skjerm-api/test"}
		ClientID:    "",
		RedirectUri: "http://localhost:8080/callback",
		PrivateKey:  your-privatekey-jwk,
	},
	HttpClient:    	   nil,
	SigningMethod: 	   nil,
})

Authorization flow

func requestHandler(hid *helseid.HelseID) http.Handler {
	router := http.NewServeMux()

	router.Handle("GET /login", helseid.AuthorizationHandler(false, nil))

	router.Handle("GET /callback", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Landingpage specified in the redirecturl
		tokenResponse, err := helseid.NewAuthorizationToken(r)
		if err != nil {
			http.Error(w, err.Error(), http.StatusUnauthorized)
			return
		}
		// Set cookie to manage the refreshtoken lifetime if needed
		http.SetCookie(w, tokenResponse.NewCookie())

		w.Write([]byte("ok"))
	}))

	return router
}

Client credentials flow (example)

func printToken(hid *helseid.HelseID) {
	tokenResponse, err := hid.NewClientCredentialToken(nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(tokenResponse.AccessToken)
}