-
-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add tested and running go sdk examples
- Loading branch information
Showing
11 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,12 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLogin(t *testing.T) { | ||
flow := initLogin() | ||
require.NotEmpty(t, flow.Id) | ||
} |
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
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,12 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRecovery(t *testing.T) { | ||
flow := initRecovery() | ||
require.NotEmpty(t, flow.Id) | ||
} |
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
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,12 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRegistration(t *testing.T) { | ||
flow := initRegistration() | ||
require.NotEmpty(t, flow.Id) | ||
} |
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,63 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/google/uuid" | ||
|
||
ory "github.com/ory/kratos-client-go" | ||
) | ||
|
||
func sdk(endpoint string) *ory.APIClient { | ||
conf := ory.NewConfiguration() | ||
conf.Servers = ory.ServerConfigurations{{URL: endpoint}} | ||
return ory.NewAPIClient(conf) | ||
} | ||
|
||
// If you use Open Source this would be: | ||
// | ||
// var c = sdk("https://127.0.0.1:4433") | ||
var c = sdk("https://playground.projects.oryapis.com/api/kratos/public") | ||
var ctx = context.Background() | ||
|
||
func initSettings() *ory.SettingsFlow { | ||
// Create a temporary user | ||
sessionToken := createUserAndGetSession() | ||
flow, _, err := c.PublicApi.InitializeSelfServiceSettingsWithoutBrowserExecute(ory.PublicApiApiInitializeSelfServiceSettingsWithoutBrowserRequest{}. | ||
XSessionToken(sessionToken)) | ||
if err != nil { | ||
log.Fatalf("An error ocurred: %s\n", err) | ||
} | ||
|
||
return flow | ||
} | ||
|
||
func main() { | ||
flow := initSettings() | ||
out, _ := json.MarshalIndent(flow, "", " ") | ||
fmt.Println(string(out)) | ||
} | ||
|
||
// createUserAndGetSession creates a user that we use for in settings flow. | ||
func createUserAndGetSession() string { | ||
flow, _, err := c.PublicApi.InitializeSelfServiceRegistrationWithoutBrowser(ctx).Execute() | ||
if err != nil { | ||
log.Fatalf("An error ocurred: %s\n", err) | ||
} | ||
|
||
result, _, err := c.PublicApi.SubmitSelfServiceRegistrationFlow(ctx).Flow(flow.Id).SubmitSelfServiceRegistrationFlow(ory.SubmitSelfServiceRegistrationFlow{ | ||
&ory.SubmitSelfServiceRegistrationFlowWithPasswordMethod{ | ||
Method: "password", | ||
Password: ory.PtrString(uuid.New().String()), | ||
Traits: map[string]interface{}{"email": "dev+" + uuid.New().String() + "@ory.sh"}, | ||
}, | ||
}).Execute() | ||
if err != nil { | ||
log.Fatalf("An error ocurred: %s\n", err) | ||
} | ||
|
||
return *result.SessionToken | ||
} |
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,12 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSettings(t *testing.T) { | ||
flow := initSettings() | ||
require.NotEmpty(t, flow.Id) | ||
} |
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
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,12 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestVerification(t *testing.T) { | ||
flow := initVerification() | ||
require.NotEmpty(t, flow.Id) | ||
} |