Back to Hydra

Go API client for openapi

internal/httpclient/README.md

26.2.014.8 KB
Original Source

Go API client for openapi

Documentation for all of Ory Hydra's APIs.

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version:
  • Package version: 1.0.0
  • Generator version: 7.14.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen

Installation

Install the following dependencies:

sh
go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context

Put the package under your project folder and add the following in import:

go
import openapi "github.com/ory/hydra-client-go/v2"

To use a proxy, set the environment variable HTTP_PROXY:

go
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value openapi.ContextServerIndex of type int.

go
ctx := context.WithValue(context.Background(), openapi.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value openapi.ContextServerVariables of type map[string]string.

go
ctx := context.WithValue(context.Background(), openapi.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration. An operation is uniquely identified by "{classname}Service.{nickname}" string. Similar rules for overriding default operation server index and variables applies by using openapi.ContextOperationServerIndices and openapi.ContextOperationServerVariables context maps.

go
ctx := context.WithValue(context.Background(), openapi.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), openapi.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Documentation for API Endpoints

All URIs are relative to http://localhost

ClassMethodHTTP requestDescription
JwkAPICreateJsonWebKeySetPost /admin/keys/{set}Create JSON Web Key
JwkAPIDeleteJsonWebKeyDelete /admin/keys/{set}/{kid}Delete JSON Web Key
JwkAPIDeleteJsonWebKeySetDelete /admin/keys/{set}Delete JSON Web Key Set
JwkAPIGetJsonWebKeyGet /admin/keys/{set}/{kid}Get JSON Web Key
JwkAPIGetJsonWebKeySetGet /admin/keys/{set}Retrieve a JSON Web Key Set
JwkAPISetJsonWebKeyPut /admin/keys/{set}/{kid}Set JSON Web Key
JwkAPISetJsonWebKeySetPut /admin/keys/{set}Update a JSON Web Key Set
MetadataAPIGetVersionGet /versionReturn Running Software Version.
MetadataAPIIsAliveGet /health/aliveCheck HTTP Server Status
MetadataAPIIsReadyGet /health/readyCheck HTTP Server and Database Status
OAuth2APIAcceptOAuth2ConsentRequestPut /admin/oauth2/auth/requests/consent/acceptAccept OAuth 2.0 Consent Request
OAuth2APIAcceptOAuth2LoginRequestPut /admin/oauth2/auth/requests/login/acceptAccept OAuth 2.0 Login Request
OAuth2APIAcceptOAuth2LogoutRequestPut /admin/oauth2/auth/requests/logout/acceptAccept OAuth 2.0 Session Logout Request
OAuth2APIAcceptUserCodeRequestPut /admin/oauth2/auth/requests/device/acceptAccepts a device grant user_code request
OAuth2APICreateOAuth2ClientPost /admin/clientsCreate OAuth 2.0 Client
OAuth2APIDeleteOAuth2ClientDelete /admin/clients/{id}Delete OAuth 2.0 Client
OAuth2APIDeleteOAuth2TokenDelete /admin/oauth2/tokensDelete OAuth 2.0 Access Tokens from specific OAuth 2.0 Client
OAuth2APIDeleteTrustedOAuth2JwtGrantIssuerDelete /admin/trust/grants/jwt-bearer/issuers/{id}Delete Trusted OAuth2 JWT Bearer Grant Type Issuer
OAuth2APIGetOAuth2ClientGet /admin/clients/{id}Get an OAuth 2.0 Client
OAuth2APIGetOAuth2ConsentRequestGet /admin/oauth2/auth/requests/consentGet OAuth 2.0 Consent Request
OAuth2APIGetOAuth2LoginRequestGet /admin/oauth2/auth/requests/loginGet OAuth 2.0 Login Request
OAuth2APIGetOAuth2LogoutRequestGet /admin/oauth2/auth/requests/logoutGet OAuth 2.0 Session Logout Request
OAuth2APIGetTrustedOAuth2JwtGrantIssuerGet /admin/trust/grants/jwt-bearer/issuers/{id}Get Trusted OAuth2 JWT Bearer Grant Type Issuer
OAuth2APIIntrospectOAuth2TokenPost /admin/oauth2/introspectIntrospect OAuth2 Access and Refresh Tokens
OAuth2APIListOAuth2ClientsGet /admin/clientsList OAuth 2.0 Clients
OAuth2APIListOAuth2ConsentSessionsGet /admin/oauth2/auth/sessions/consentList OAuth 2.0 Consent Sessions of a Subject
OAuth2APIListTrustedOAuth2JwtGrantIssuersGet /admin/trust/grants/jwt-bearer/issuersList Trusted OAuth2 JWT Bearer Grant Type Issuers
OAuth2APIOAuth2AuthorizeGet /oauth2/authOAuth 2.0 Authorize Endpoint
OAuth2APIOAuth2DeviceFlowPost /oauth2/device/authThe OAuth 2.0 Device Authorize Endpoint
OAuth2APIOauth2TokenExchangePost /oauth2/tokenThe OAuth 2.0 Token Endpoint
OAuth2APIPatchOAuth2ClientPatch /admin/clients/{id}Patch OAuth 2.0 Client
OAuth2APIPerformOAuth2DeviceVerificationFlowGet /oauth2/device/verifyOAuth 2.0 Device Verification Endpoint
OAuth2APIRejectOAuth2ConsentRequestPut /admin/oauth2/auth/requests/consent/rejectReject OAuth 2.0 Consent Request
OAuth2APIRejectOAuth2LoginRequestPut /admin/oauth2/auth/requests/login/rejectReject OAuth 2.0 Login Request
OAuth2APIRejectOAuth2LogoutRequestPut /admin/oauth2/auth/requests/logout/rejectReject OAuth 2.0 Session Logout Request
OAuth2APIRevokeOAuth2ConsentSessionsDelete /admin/oauth2/auth/sessions/consentRevoke OAuth 2.0 Consent Sessions of a Subject
OAuth2APIRevokeOAuth2LoginSessionsDelete /admin/oauth2/auth/sessions/loginRevokes OAuth 2.0 Login Sessions by either a Subject or a SessionID
OAuth2APIRevokeOAuth2TokenPost /oauth2/revokeRevoke OAuth 2.0 Access or Refresh Token
OAuth2APISetOAuth2ClientPut /admin/clients/{id}Set OAuth 2.0 Client
OAuth2APISetOAuth2ClientLifespansPut /admin/clients/{id}/lifespansSet OAuth2 Client Token Lifespans
OAuth2APITrustOAuth2JwtGrantIssuerPost /admin/trust/grants/jwt-bearer/issuersTrust OAuth2 JWT Bearer Grant Type Issuer
OidcAPICreateOidcDynamicClientPost /oauth2/registerRegister OAuth2 Client using OpenID Dynamic Client Registration
OidcAPICreateVerifiableCredentialPost /credentialsIssues a Verifiable Credential
OidcAPIDeleteOidcDynamicClientDelete /oauth2/register/{id}Delete OAuth 2.0 Client using the OpenID Dynamic Client Registration Management Protocol
OidcAPIDiscoverOidcConfigurationGet /.well-known/openid-configurationOpenID Connect Discovery
OidcAPIGetOidcDynamicClientGet /oauth2/register/{id}Get OAuth2 Client using OpenID Dynamic Client Registration
OidcAPIGetOidcUserInfoGet /userinfoOpenID Connect Userinfo
OidcAPIRevokeOidcSessionGet /oauth2/sessions/logoutOpenID Connect Front- and Back-channel Enabled Logout
OidcAPISetOidcDynamicClientPut /oauth2/register/{id}Set OAuth2 Client using OpenID Dynamic Client Registration
WellknownAPIDiscoverJsonWebKeysGet /.well-known/jwks.jsonDiscover Well-Known JSON Web Keys

Documentation For Models

Documentation For Authorization

Authentication schemes defined for the API:

basic

  • Type: HTTP basic authentication

Example

go
auth := context.WithValue(context.Background(), openapi.ContextBasicAuth, openapi.BasicAuth{
	UserName: "username",
	Password: "password",
})
r, err := client.Service.Operation(auth, args)

bearer

  • Type: HTTP Bearer token authentication

Example

go
auth := context.WithValue(context.Background(), openapi.ContextAccessToken, "BEARER_TOKEN_STRING")
r, err := client.Service.Operation(auth, args)

oauth2

  • Type: OAuth
  • Flow: accessCode
  • Authorization URL: https://hydra.demo.ory.sh/oauth2/auth
  • Scopes:
  • offline: A scope required when requesting refresh tokens (alias for offline_access)
  • offline_access: A scope required when requesting refresh tokens
  • openid: Request an OpenID Connect ID Token

Example

go
auth := context.WithValue(context.Background(), openapi.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)

Or via OAuth2 module to automatically refresh tokens and perform user authentication.

go
import "golang.org/x/oauth2"

/* Perform OAuth2 round trip request and obtain a token */

tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
auth := context.WithValue(oauth2.NoContext, openapi.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author

[email protected]