Skip to content

Latest commit

 

History

History
88 lines (60 loc) · 1.6 KB

File metadata and controls

88 lines (60 loc) · 1.6 KB

Getting Started

Create a new OAuthClient

Public client

issuer := "https://as.example.com"
clientId := "my_client_id"

ctx := context.Background()

// fetch '/.well-known/openid-configuration'
wk, err := oauthx.NewWellKnownOpenidConfiguration(ctx, issuer)
if err != nil {
  panic(err)
}

// create OAuthClient with default option (auth method 'none')
client := oauthx.NewOAuthClient(clientId, wk)

ClientSecretPost

issuer := "https://as.example.com"
clientId := "my_client_id"
clientSecret := "my_secret"

auth := oauthx.NewClientSecretPost(clientId, clientSecret)

ctx := context.Background()


// fetch '/.well-known/openid-configuration'
wk, err := oauthx.NewWellKnownOpenidConfiguration(ctx, issuer)
if err != nil {
  panic(err)
}

// create OAuthClient 
client := oauthx.NewOAuthClient(clientId, wk,
	oauthx.WithAuthMethod(auth),
)

PrivateKeyJwt

issuer := "https://as.example.com"
clientId := "my_client_id"

// crypto.PrivateKey
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
  panic(err)
}

// leave the staticKid empty to generate the kid based on 
// a hash of the public key
oauthkey, err = oauthx.NewOAuthPrivateKey(privateKey, "RS256", "")
if err != nil {
  panic(err)
}

// create priavate_key_jwt with default options
auth := oauthx.NewPrivateKeyJwt(clientId, oauthkey)

ctx := context.Background()


// fetch '/.well-known/openid-configuration'
wk, err := oauthx.NewWellKnownOpenidConfiguration(ctx, issuer)
if err != nil {
  panic(err)
}

// create OAuthClient 
client := oauthx.NewOAuthClient(clientId, wk,
	oauthx.WithAuthMethod(auth),
)