forked from auth0/go-auth0
-
Notifications
You must be signed in to change notification settings - Fork 1
/
doc.go
129 lines (98 loc) · 3.17 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Package auth0 provides a client for using the Auth0 Authentication and Management APIs.
# Authentication
# Usage
import (
"github.com/ConsultingMD/go-auth0"
"github.com/ConsultingMD/go-auth0/authentication"
"github.com/ConsultingMD/go-auth0/authentication/database"
"github.com/ConsultingMD/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/ConsultingMD/go-auth0"
"github.com/ConsultingMD/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