Skip to content

Commit 474b4e5

Browse files
authored
added login method
1 parent d882d2d commit 474b4e5

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

keycloak/api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import (
55
"github.com/Nerzal/gocloak/v10"
66
)
77

8+
/*
9+
*/
10+
func (g *gkeycloak) Login(username string, password string) (*gocloak.JWT, error) {
11+
token, err := g.client.Login(g.ctx, g.clientId, g.clientSecret, username, password )
12+
if err != nil {
13+
return nil, err
14+
}
15+
return token, nil
16+
}
817
/*
918
*/
1019
func (g *gkeycloak) GetToken(tokenOptions gocloak.TokenOptions) (*gocloak.JWT, error) {

keycloak/keycloak.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ type gkeycloak struct {
2323
type IKeycloak interface {
2424
//
2525
IsDebug() bool
26+
Login(username string, password string) (*gocloak.JWT, error)
2627
GetToken( tokenOptions gocloak.TokenOptions ) (*gocloak.JWT, error)
2728
RefreshToken( refreshToken string ) (*gocloak.JWT, error)
2829
Logout(refreshToken string) error
2930
GetUserEmail( email string) (*gocloak.User, error)
3031
UpdateUser( firstName string, lastName string, username string, attributes map[string][]string, realmRoles []string) (bool, error)
31-
LoginTokenOptions() gocloak.TokenOptions
32+
//LoginTokenOptions() gocloak.TokenOptions
3233
//
3334
}
3435

keycloak/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/Nerzal/gocloak/v10"
55
)
66

7-
func (g *gkeycloak) LoginTokenOptions() gocloak.TokenOptions {
7+
func (g *gkeycloak) loginTokenOptions() gocloak.TokenOptions {
88
grant := GRANT_PASSWORD
99
return gocloak.TokenOptions{
1010
GrantType: &grant,

0 commit comments

Comments
 (0)