sdk

package
v0.4.2-alpha.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2016 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package SDK offers convenience functions for Go code around Hydra's HTTP APIs.

 import "github.com/ory-am/hydra/sdk"
 import "github.com/ory-am/hydra/client"

 var hydra, err = sdk.Connect(
	sdk.ClientID("client-id"),
	sdk.ClientSecret("client-secret"),
 	sdk.ClusterURL("https://localhost:4444"),
 )

 // You now have access to the various API endpoints of hydra, for example the oauth2 client endpoint:
 var newClient, err = hydra.Client.CreateClient(&client.Client{
 	ID:                "deadbeef",
 	Secret:            "sup3rs3cret",
 	RedirectURIs:      []string{"http://yourapp/callback"},
 	// ...
 })

 // Retrieve newly created client
 var gotClient, err = hydra.Client.GetClient(newClient.ID)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientID

func ClientID(id string) option

ClientID sets the OAuth2 Client ID.

 var hydra, err = sdk.Connect(
	sdk.ClientID("client-id"),
 )

func ClientSecret

func ClientSecret(secret string) option

ClientSecret sets OAuth2 Client secret.

 var hydra, err = sdk.Connect(
	sdk.ClientSecret("client-secret"),
 )

func ClusterURL

func ClusterURL(urlStr string) option

ClusterURL sets Hydra service URL

 var hydra, err = sdk.Connect(
	sdk.ClientID("https://localhost:1234/"),
 )

func FromYAML

func FromYAML(file string) option

FromYAML loads configurations from a YAML file

func Scopes

func Scopes(scopes ...string) option

Scopes is a list of scopes that are requested in the client credentials grant.

var hydra, err = sdk.Connect(
	sdk.Scopes("foo", "bar"),
)

func SkipTLSVerify

func SkipTLSVerify() option

SkipTLSVerify skips TLS verification for HTTPS connections.

 var hydra, err = sdk.Connect(
	sdk.SkipTLSVerify(),
 )

Types

type Client

type Client struct {
	// Client offers OAuth2 Client management capabilities.
	Client *client.HTTPManager

	// SSO offers Social Login management capabilities.
	SSO *connection.HTTPManager

	// JWK offers JSON Web Key management capabilities.
	JWK *jwk.HTTPManager

	// Policies offers Access Policy management capabilities.
	Policies *policy.HTTPManager

	// Warden offers Access Token and Access Request validation strategies.
	Warden *warden.HTTPWarden

	Introspector *hoauth2.HTTPIntrospector
	// contains filtered or unexported fields
}

Client offers easy use of all HTTP clients.

func Connect

func Connect(opts ...option) (*Client, error)

Connect instantiates a new client to communicate with Hydra.

 import "github.com/ory-am/hydra/sdk"

 var hydra, err = sdk.Connect(
	sdk.ClientID("client-id"),
	sdk.ClientSecret("client-secret"),
 	sdk.ClusterURL("https://localhost:4444"),
 )

func (*Client) OAuth2Config added in v0.4.0

func (h *Client) OAuth2Config(redirectURL string, scopes ...string) *oauth2.Config

OAuth2Config returns an oauth2 config instance which you can use to initiate various oauth2 flows.

config := client.OAuth2Config("https://mydomain.com/oauth2_callback", "photos", "contacts.read")
redirectRequestTo := oauth2.AuthCodeURL()

// in callback handler...
token, err := config.Exchange(oauth2.NoContext, authorizeCode)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL