liboidcagent-go
A go library for oidc-agent is available at https://github.com/indigo-dc/liboidcagent-go.
To use it in your go application do
go get github.com/indigo-dc/liboidc-agent-goand include:
import "github.com/indigo-dc/liboidcagent-go"Requesting an Access Token
The following functions can be used to obtain an access token for a specific account configuration or for a given OpenID provider from oidc-agent.
Token Request
All functions take a TokenRequest struct. This struct describes the request:
// TokenRequest is used to request an access token from the agent
type TokenRequest struct {
// ShortName that should be used (Can be omitted if IssuerURL is specified)
ShortName string
// IssuerURL for which an access token should be obtained (Can be omitted
// if ShortName is specified)
IssuerURL string
// MinValidPeriod specifies how long the access token should be valid at
// least. The time is given in seconds. Default is 0.
MinValidPeriod uint64
// The scopes for the requested access token
Scopes []string
// The audiences for the requested access token
Audiences []string
// A string describing the requesting application (i.e. its name). It might
// be displayed to the user, if the request must be confirmed or an account
// configuration loaded.
ApplicationHint string
}GetAccessToken
This function requests an access token from oidc-agent according to the passed TokenRequest.
Return Value
The function returns only the access token as a string and an error. To additionally obtain other information use GetTokenResponse. On failure an error is returned.
Examples
Account Configuration Example
A complete example can look the following:
Issuer Example
A complete example can look the following:
GetTokenResponse
This function requests an access token from oidc-agent according to the passed TokenRequest.
Return Value
The function returns an TokenResponse struct that contains the requested access token, the url of the issuer that issued the token and the time when the token expires.
The values can be accessed the following way:
Examples
Account Configuration Example
A complete example can look the following:
Issuer Example
A complete example can look the following:
Requesting a Mytoken
The following functions can be used to obtain a mytoken from oidc-agent.
Mytoken Request
All functions take a MytokenRequest struct. This struct describes the request:
GetMytoken
This function requests a mytoken from oidc-agent according to the passed MytokenRequest.
Return Value
The function returns only the mytoken as a string and an error. To additionally obtain other information use GetMytokenResponse. On failure an error is returned.
Example
A complete example can look the following:
GetMytokenResponse
This function requests a mytoken from oidc-agent according to the passed MytokenRequest.
Return Value
The function returns a MytokenResponse struct that contains the requested token, as well as other information.
The values can be accessed the following way:
There are additional fields available from the mytoken API's MytokenResponse struct which is included in this libraries MytokenResponse struct.
Example
A complete example can look the following:
Getting Loaded Accounts
This function requests the list of currently loaded accounts from oidc-agent.
Return Value
The function returns a list of the currently loaded accounts as a []string on success and an OIDCAgentError on failure.
Getting Configured Accounts
This function checks the oidc-agent directory for the configured accounts.
Return Value
The function returns a list of the configured accounts as a []string.
Last updated