Skip to content

Latest commit

 

History

History
116 lines (81 loc) · 3.57 KB

File metadata and controls

116 lines (81 loc) · 3.57 KB

auth

import "github.com/greenbone/opensight-golang-libraries/pkg/auth"

Package auth provides a client to authenticate against a Keycloak server.

Index

ClientCredentials to authenticate via `Client credentials grant` flow. Ref: https://www.keycloak.org/docs/latest/server_admin/index.html#_client_credentials_grant

type ClientCredentials struct {
    ClientID     string
    ClientSecret string
}

type Clock

type Clock interface {
    Now() time.Time
}

Credentials holds the required credentials and determines the used auth type.

type Credentials interface {
    // contains filtered or unexported methods
}

KeycloakClient can be used to authenticate against a Keycloak server.

type KeycloakClient struct {
    // contains filtered or unexported fields
}

func NewKeycloakClient(httpClient *http.Client, cfg KeycloakConfig, credentials Credentials) *KeycloakClient

NewKeycloakClient creates a new KeycloakClient. Passed Credentials determines the used auth type.

func (*KeycloakClient) GetToken

func (c *KeycloakClient) GetToken(ctx context.Context) (string, error)

GetToken retrieves a valid access token. The token is cached and refreshed before expiry.

KeycloakConfig holds the credentials and configuration details

type KeycloakConfig struct {
    AuthURL       string
    KeycloakRealm string
}

ResourceOwnerCredentials to authenticate via `Resource owner password credentials grant` flow. Ref: https://www.keycloak.org/docs/latest/server_admin/index.html#_oidc-auth-flows-direct

type ResourceOwnerCredentials struct {
    ClientID string
    Username string
    Password string
}

Generated by gomarkdoc