-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split godoc into separate packages (#311)
- Loading branch information
1 parent
074738c
commit 824469a
Showing
3 changed files
with
281 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Package authentication provides a client for using the Auth0 Authentication API. | ||
// | ||
// # Usage | ||
// | ||
// import ( | ||
// "github.com/auth0/go-auth0" | ||
// "github.com/auth0/go-auth0/authentication" | ||
// "github.com/auth0/go-auth0/authentication/database" | ||
// "github.com/auth0/go-auth0/authentication/oauth" | ||
// ) | ||
// a, err := authentication.New( | ||
// context.TODO(), | ||
// domain, | ||
// authentication.WithClientID(id), | ||
// authentication.WithClientSecret(secret), // Optional depending on the grants used | ||
// ) | ||
// if err != nil { | ||
// // handle err | ||
// } | ||
// // Now we have an authentication client, we can interact with the Auth0 Authentication API. | ||
// // Sign up a user | ||
// userData := database.SignupRequest{ | ||
// Connection: "Username-Password-Authentication", | ||
// Username: "mytestaccount", | ||
// Password: "mypassword", | ||
// Email: "[email protected]", | ||
// } | ||
// createdUser, err := a.Database.Signup(context.TODO(), userData) | ||
// if err != nil { | ||
// // handle err | ||
// } | ||
// // Login using OAuth grants | ||
// tokenSet, err := a.OAuth.LoginWithAuthCodeWithPKCE(context.TODO(), oauth.LoginWithAuthCodeWithPKCERequest{ | ||
// Code: "test-code", | ||
// CodeVerifier: "test-code-verifier", | ||
// }, oauth.IDTokenValidationOptionalVerification{}) | ||
// | ||
// if err != nil { | ||
// // handle err | ||
// } | ||
// | ||
// # Configuration | ||
// | ||
// There are several options that can be specified during the creation of a client. | ||
// For a complete list see [Option]. | ||
// | ||
// a, err := authentication.New( | ||
// context.TODO(), | ||
// domain, | ||
// authentication.WithClientID(id), | ||
// authentication.WithClientSecret(secret), // Optional depending on the grants used | ||
// authentication.WithClockTolerance(10 * time.Second), | ||
// ) | ||
package authentication |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,75 @@ | ||
/* | ||
Package auth0 provides a client for using the Auth0 Authentication and Management APIs. | ||
# Authentication | ||
# Usage | ||
import ( | ||
"github.com/auth0/go-auth0" | ||
"github.com/auth0/go-auth0/authentication" | ||
"github.com/auth0/go-auth0/authentication/database" | ||
"github.com/auth0/go-auth0/authentication/oauth" | ||
) | ||
Initialize a new client using a context, domain, client ID, and client secret if required. | ||
authAPI, err := authentication.New( | ||
context.Background(), | ||
domain, | ||
authentication.WithClientID(id), | ||
authentication.WithClientSecret(secret), // Optional depending on the grants used | ||
) | ||
if err != nil { | ||
// handle err | ||
} | ||
Now we have an authentication client, we can interact with the Auth0 Authentication API. | ||
// Sign up a user | ||
userData := database.SignupRequest{ | ||
Connection: "Username-Password-Authentication", | ||
Username: "mytestaccount", | ||
Password: "mypassword", | ||
Email: "[email protected]", | ||
} | ||
createdUser, err := authAPI.Database.Signup(context.Background(), userData) | ||
if err != nil { | ||
// handle err | ||
} | ||
// Login using OAuth grants | ||
tokenSet, err := authAPI.OAuth.LoginWithAuthCodeWithPKCE(context.Background(), oauth.LoginWithAuthCodeWithPKCERequest{ | ||
Code: "test-code", | ||
CodeVerifier: "test-code-verifier", | ||
}, oauth.IDTokenValidationOptionalVerification{}) | ||
if err != nil { | ||
// handle err | ||
} | ||
# Management | ||
Usage | ||
import ( | ||
"github.com/auth0/go-auth0" | ||
"github.com/auth0/go-auth0/management" | ||
) | ||
Initialize a new client using a domain, client ID and secret. | ||
m, err := management.New( | ||
domain, | ||
management.WithClientCredentials(context.Background(), id, secret), | ||
) | ||
if err != nil { | ||
// handle err | ||
} | ||
Or using a static token. | ||
m, err := management.New(domain, management.WithStaticToken(token)) | ||
if err != nil { | ||
// handle err | ||
} | ||
With a management client we can then interact with the Auth0 Management API. | ||
c := &management.Client{ | ||
Name: auth0.String("Client Name"), | ||
Description: auth0.String("Long description of client"), | ||
} | ||
err = m.Client.Create(context.Background(), c) | ||
if err != nil { | ||
// handle err | ||
} | ||
## Authentication | ||
The auth0 management package handles authentication by exchanging the client ID and secret | ||
supplied when creating a new management client. | ||
This is handled internally using the https://godoc.org/golang.org/x/oauth2 | ||
package. | ||
## Rate Limiting | ||
The auth0 package also handles rate limiting by respecting the `X-Rate-Limit-*` | ||
headers sent by the server. | ||
The amount of time the client waits for the rate limit to be reset is taken from | ||
the `X-Rate-Limit-Reset` header as the amount of seconds to wait. | ||
# Configuration | ||
There are several other options that can be specified during the creation of a | ||
new client. | ||
m, err := management.New( | ||
domain, | ||
management.WithClientCredentials(context.Background(), id, secret), | ||
management.WithDebug(true), | ||
) | ||
## Request Options | ||
As with the global client configuration, fine-grained configuration can be done | ||
on a request basis. | ||
c, err := m.Connection.List( | ||
context.Background(), | ||
management.Page(2), | ||
management.PerPage(10), | ||
management.IncludeFields("id", "name", "options"), | ||
management.Parameter("strategy", "auth0"), | ||
) | ||
*/ | ||
// Package auth0 is the Auth0 SDK for Go. | ||
// | ||
// The SDK provides clients that interact with the Auth0 Authentication and Management APIs | ||
// and is split into separate packages as such. | ||
// | ||
// - auth0 - Provides helpers for providing values as pointers. | ||
// - authentication - Provides an Authentication Client for use when interacting with the | ||
// [Authentication API]. | ||
// - management - Provides a Management Client for use when interacting with the Auth0 | ||
// [Management API]. | ||
// | ||
// # Getting Started | ||
// | ||
// Install the SDK using `go get` | ||
// | ||
// go get github.com/auth0/go-auth0 | ||
// | ||
// # Authentication | ||
// | ||
// Below is an example of using the Authentication client, for full documentation visit the | ||
// [authentication client docs]. | ||
// | ||
// authAPI, err := authentication.New( | ||
// context.TODO(), | ||
// domain, | ||
// authentication.WithClientID(id), | ||
// authentication.WithClientSecret(secret), // Optional depending on the grants used | ||
// ) | ||
// if err != nil { | ||
// // handle err | ||
// } | ||
// // Now we have an authentication client, we can interact with the Auth0 Authentication API. | ||
// // Sign up a user | ||
// userData := database.SignupRequest{ | ||
// Connection: "Username-Password-Authentication", | ||
// Username: "mytestaccount", | ||
// Password: "mypassword", | ||
// Email: "[email protected]", | ||
// } | ||
// createdUser, err := authAPI.Database.Signup(context.TODO(), userData) | ||
// if err != nil { | ||
// // handle err | ||
// } | ||
// | ||
// # Management | ||
// | ||
// Below is an example of using the Management client, for full documentation visit the | ||
// [management client docs]. | ||
// | ||
// import ( | ||
// "github.com/auth0/go-auth0" | ||
// "github.com/auth0/go-auth0/management" | ||
// ) | ||
// // Initialize a new client using a domain, client ID and secret. | ||
// m, err := management.New( | ||
// domain, | ||
// management.WithClientCredentials(context.TODO(), id, secret), | ||
// ) | ||
// if err != nil { | ||
// // handle err | ||
// } | ||
// c := &management.Client{ | ||
// Name: auth0.String("Client Name"), | ||
// Description: auth0.String("Long description of client"), | ||
// } | ||
// err = m.Client.Create(context.TODO(), c) | ||
// if err != nil { | ||
// // handle err | ||
// } | ||
// | ||
// [management client docs]: https://pkg.go.dev/github.com/auth0/go-auth0/management | ||
// [Authentication API]: https://auth0.com/docs/api/authentication | ||
// [Management API]: https://auth0.com/docs/api/management/v2 | ||
// [authentication client docs]: https://pkg.go.dev/github.com/auth0/go-auth0/authentication | ||
package auth0 |
Oops, something went wrong.