Skip to content

Commit

Permalink
added get Token
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan-Nava authored Nov 16, 2023
1 parent 618c4dd commit ef799c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
13 changes: 13 additions & 0 deletions keycloak/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package keycloak

import (
"gocloak.JWT"

Check failure on line 4 in keycloak/api.go

View workflow job for this annotation

GitHub Actions / build (1.18.x)

no required module provides package gocloak.JWT; to add it:

Check failure on line 4 in keycloak/api.go

View workflow job for this annotation

GitHub Actions / build (1.19.x)

no required module provides package gocloak.JWT; to add it:

Check failure on line 4 in keycloak/api.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

no required module provides package gocloak.JWT; to add it:

Check failure on line 4 in keycloak/api.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

no required module provides package gocloak.JWT; to add it:
)

func (g *gkeycloak) GetToken( tokenOptions gocloak.TokenOptions ) (*JWT, error) {
token, err := g.GCloakClient.GetToken(g.ctx, g.realm, tokenOptions)
if err != nil {
return, nil, err
}
return token, nil
}
9 changes: 9 additions & 0 deletions keycloak/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package keycloak

const (
GRANT_CLIENT_CREDENTIALS = "client_credentials"
GRANT_PASSWORD = "password"
REALM_MANAGEMENT_CLIENT = "realm-management"
ERROR_401_UNATHORIZED = "401 Unauthorized: HTTP 401 Unauthorized"
ERROR_CLIENT_SECRET_NOT_PROVIDED = "Client secret not provided in request"
)
7 changes: 6 additions & 1 deletion keycloak/keycloak.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keycloak

import (
"context"
"sync"
"github.com/Nerzal/gocloak/v10"
)
Expand All @@ -17,10 +18,12 @@ type gkeycloak struct {

type IKeycloak interface {
IsDebug() bool
GetToken( tokenOptions gocloak.TokenOptions ) (*JWT, error)
}

func NewKeycloak(realm string, server string, clientId string, clientSecret string, isDebug bool) (IKeycloak, error) {
func NewKeycloak(ctx context.Context, realm string, server string, clientId string, clientSecret string, isDebug bool) (IKeycloak, error) {
k := &gkeycloak{
ctx: ctx,
debug: isDebug,
clientId: clientId,
clientSecret: clientSecret,
Expand All @@ -33,6 +36,8 @@ func NewKeycloak(realm string, server string, clientId string, clientSecret stri
return k, nil
}

//

func (g *gkeycloak) IsDebug() bool {
return g.debug
}

0 comments on commit ef799c5

Please sign in to comment.