You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -15,69 +17,16 @@ go get github.com/kinde-oss/kinde-go
15
17
go mod tidy
16
18
```
17
19
18
-
## Autorization code flow
19
-
20
-
`authorization_code` package, imported as `github.com/kinde-oss/kinde-go/oauth2/authorization_code`.
21
-
22
-
This is a backend authorization flow, which requires slient secret. It is designed to be used as a server-side auth flow and not exposes tokens to the browser. The user session needs to be managed by other means, for example via the session cookie.
authorization_code.WithSessionHooks(<ISessionHooks implementation>), //example of storage for gin framework is gin_kinde.UseKindeAuth(...)
30
-
authorization_code.WithOffline(), //adds offline scope and starts managing refresh tokens
31
-
authorization_code.WithAudience("<your API audience>"), //requesting an API audience
32
-
authorization_code.WithTokenValidation(
33
-
true, // will validate token signature via JWKS
34
-
jwt.WillValidateAlgorithm(), // will validate the token alg is RS256
35
-
jwt.WillValidateAudience("<your API audience>"), // will confirm that received token includes correct audience
36
-
),
37
-
)
38
-
39
-
```
40
-
41
-
`kindeAuthFlow` provides the following methods:
20
+
## Authorization Code Flow
42
21
43
-
| Method | Description | Parameters | Returns |
44
-
| --- | --- | --- | --- |
45
-
|`GetAuthURL`| Returns the URL to redirect the user to start the authentication pipeline. | none |`string`|
46
-
|`ExchangeCode`| Exchanges the authorization code for a token and establishes KindeContext. | ctx `context.Context`, authorizationCode `string`, receivedState `string`|`error`|
47
-
|`GetClient`| Returns an HTTP client for calling external services, automatically refreshing tokens if offline is requested. | ctx `context.Context`|`(*http.Client, error)`|
48
-
|`IsAuthenticated`| Checks if the user is authenticated. | ctx `context.Context`|`(bool, error)`|
49
-
|`Logout`| Clears local tokens and logs the user out. | none |`error`|
50
-
|`AuthorizationCodeReceivedHandler`| Helper handler middleware for the code exchanger. | w `http.ResponseWriter`, r `*http.Request`| none |
51
-
52
-
### Device authorization flow
22
+
For comprehensive information about the authorization code flow and device authorization flow, see [oauth2/authorization_code/README.md](oauth2/authorization_code/README.md).
53
23
54
-
`authorization_code` package, imported as `github.com/kinde-oss/kinde-go/oauth2/authorization_code`.
24
+
The `authorization_code` package provides OAuth2 authorization code flow implementations for Go applications, including:
55
25
56
-
This is an extension of authorization code flow, which separatees token requester and receiver. It is best used for devices and environment with the limited input capabilities, e.g. CLIs, TVs etc.
"<issuer_domain>", // Kinde subdomain or any auth provider conforming to the spec
61
-
authorization_code.WithClientID(), // optional, when business provides a default device applicaiton, otherwise required
62
-
authorization_code.WithClientSecret(), // optional (used when device flow is used against backend application with a secret)
63
-
authorization_code.WithSessionHooks(<ISessionHooks implementation>), // used for storing/retreiving tokens
64
-
authorization_code.WithOffline(), // optional - include if you'd like to maintain refresh tokens and a long session
65
-
authorization_code.WithTokenValidation(
66
-
true, // will validate token signature via JWKS
67
-
jwt.WillValidateAlgorithm(), // will validate the token alg is RS256
68
-
)
69
-
```
70
-
71
-
`deviceFlow` will provide following methods
72
-
73
-
| Method | Description | Parameters | Returns |
74
-
| --- | --- | --- | --- |
75
-
|`StartDeviceAuth`| Starts the device authorization flow and returns the device authorization response. | ctx `context.Context`|`(*oauth2.DeviceAuthResponse, error)`|
76
-
|`ExchangeDeviceAccessToken`| Exchanges the device code for an access token. | ctx `context.Context`, da `*oauth2.DeviceAuthResponse`, opts `...oauth2.AuthCodeOption`|`error`|
77
-
|`GetClient`| Returns an HTTP client for calling external services, automatically refreshing tokens if offline is requested. | ctx `context.Context`|`(*http.Client, error)`|
78
-
|`IsAuthenticated`| Checks if the user is authenticated. | ctx `context.Context`|`(bool, error)`|
79
-
|`Logout`| Clears local tokens and logs the user out. | none |`error`|
80
-
|`GetToken`| Returns the token for the current session. | ctx `context.Context`|`(*jwt.Token, error)`|
26
+
- Standard authorization code flow for web applications
27
+
- Device authorization flow for devices with limited input capabilities
"<client_secret>", // required for client_credentials
95
44
client_credentials.WithAudience("[your API audience]"), // optioanlly include your API audience
96
45
client_credentials.WithScopes() // optional - request API scopes
97
-
client_credentials.WithKindeManagementAPI("<https://my_kinde_tenant.kinde.com>"), // adds kinde management API audience
46
+
client_credentials.WithKindeManagementAPI("<https://my_kinde_tenant.kinde.com>"), // adds kinde management API audience - see README_MANAGEMENT_API.md for details
98
47
client_credentials.WithSessionHooks(<ISessionHooks implementation>), // example of CLI is cli.NewCliSession(...)
99
48
client_credentials.WithTokenValidation( // validates tokens when a new token is aquired
// handle initialization error (e.g., invalid config or token source)
74
+
log.Fatalf("failed to init client: %v", err)
75
+
}
127
76
```
128
77
129
-
### Calling Kinde Management API
130
-
131
-
`kinde` package, imported with `github.com/kinde-oss/kinde-go/kinde`.
132
-
133
-
Please note, Kinde management API is only accessible via M2M applications with Management API enabled and limited by the authorized scopes.
134
-
135
-
You can have multiple applications configured with different levels of access.
136
-
137
-
Kinde uses generated code to map OpenAPI specification to go.
78
+
// example call to Kinde Management API (client needs WithKindeManagementAPI(...)) - see README_MANAGEMENT_API.md for details response, err := client.Get("<anauthorizedURL>")
138
79
139
-
```go
140
-
managementApi, err:= kinde.NewManagementAPI(ctx, "<kinde domain>", <client credentials flow>) //management API uses client credentials flow described earlier
This call returns `CreateApplicationRes` interface, which can be one of the following:
82
+
For comprehensive information about using the Kinde Management API, including authentication, setup, and usage examples, see [README_MANAGEMENT_API.md](README_MANAGEMENT_API.md).
The Management API allows you to programmatically manage your Kinde tenant, including creating applications, managing users, configuring settings, and more. It requires M2M applications with Management API enabled and appropriate scopes configured.
160
85
161
86
### JWT Package
162
87
@@ -170,6 +95,21 @@ The `jwt` package provides comprehensive JWT parsing, validation, and management
170
95
- Comprehensive token information access
171
96
- Seamless integration with OAuth2 flows
172
97
98
+
## Examples
99
+
100
+
This repository includes several examples demonstrating different authentication flows:
0 commit comments