github.com/brioux/go-keycloak@v0.0.0-20240929191119-b54a3a01d90b/README.md (about)

     1  # go-keycloak
     2  
     3  go-keycloak is a Go client library for accessing the [Keycloak API](https://www.keycloak.org/documentation.html)
     4  
     5  ## Usage
     6  
     7  ```go
     8  import "github.com/hugocortes/go-keycloak"
     9  ```
    10  
    11  Constructing the Keycloak client depends on the client that will be used to make requests and if that user or client has offline access to disable the SSO idle timeout. This provides flexibiliy in creating more than one Keycloak client to authenticate against different realms and/or clients.
    12  
    13  1. Using a Service Account will require the client ID, client name, and the client secret
    14  ```go
    15  // Creates a service account
    16  serviceAccount := keycloak.NewServiceAccount(
    17  	httpClient, // httpClient or use default if nil
    18  	"BASE_URL", // base keycloak url
    19  	"REALM", // target realm
    20  	hasOfflineAccess, // If offline_access role is assigned
    21  	"CLIENT_ID", // target client id
    22  	"CLIENT_NAME", // target client name
    23  	"CLIENT_SECRET", // target client secret
    24  )
    25  ```
    26  2. Using a user to authenticate using a confidential client will require client ID, client name, client secret, admin, and admin password
    27  ```go
    28  // Creates a service account
    29  serviceAccount := keycloak.NewConfidentialAdmin(
    30  	httpClient, // httpClient or use default if nil
    31  	"BASE_URL", // base keycloak url
    32  	"REALM", // target realm
    33  	hasOfflineAccess, // If offline_access role is assigned
    34  	"CLIENT_ID", // target client id
    35  	"CLIENT_NAME", // target client name
    36  	"CLIENT_SECRET", // target client secret
    37  	"ADMION_USER", // target admin username
    38  	"ADMIN_PASS", // target admin password
    39  )
    40  ```
    41  3. User a user to authenticate using a public client will require client ID, client name, admin, and admin password
    42  ```go
    43  // Creates a service account
    44  serviceAccount := keycloak.NewPublicAdmin(
    45  	httpClient, // httpClient or use default if nil
    46  	"BASE_URL", // base keycloak url
    47  	"REALM", // target realm
    48  	hasOfflineAccess, // If offline_access role is assigned
    49  	"CLIENT_ID", // target client id
    50  	"CLIENT_NAME", // target client name
    51  	"ADMION_USER", // target admin username
    52  	"ADMIN_PASS", // target admin password
    53  )
    54  ```
    55  
    56  Note: Depending on the type of request, the library will require the Client (if full scope mapping is disbled) and Admin User and/or Service Account to have the appropriate role(s) or 403 errors will be returned.