snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
This commit is contained in:
61
examples/go/pkg/common.go
Normal file
61
examples/go/pkg/common.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
ory "github.com/ory/client-go"
|
||||
"github.com/ory/kratos/pkg/testhelpers"
|
||||
"github.com/ory/kratos/x"
|
||||
)
|
||||
|
||||
func PrintJSONPretty(v interface{}) {
|
||||
out, _ := json.MarshalIndent(v, "", " ")
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
func TestClient(t *testing.T) *ory.APIClient {
|
||||
publicURL, _ := testhelpers.StartE2EServer(t, "../../pkg/stub/kratos.yaml", nil)
|
||||
return NewSDKForSelfHosted(publicURL)
|
||||
}
|
||||
|
||||
func NewSDK(project string) *ory.APIClient {
|
||||
return NewSDKForSelfHosted(fmt.Sprintf("https://%s.projects.oryapis.com/api/kratos/public", project))
|
||||
}
|
||||
|
||||
func NewSDKForSelfHosted(endpoint string) *ory.APIClient {
|
||||
conf := ory.NewConfiguration()
|
||||
conf.Servers = ory.ServerConfigurations{{URL: endpoint}}
|
||||
cj, _ := cookiejar.New(nil)
|
||||
conf.HTTPClient = &http.Client{Jar: cj}
|
||||
return ory.NewAPIClient(conf)
|
||||
}
|
||||
|
||||
func ExitOnError(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
out, _ := json.MarshalIndent(err, "", " ")
|
||||
fmt.Printf("%s\n\nAn error occurred: %+v\n", out, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func SDKExitOnError(err error, res *http.Response) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
var body []byte
|
||||
if res != nil {
|
||||
body, _ = json.MarshalIndent(json.RawMessage(x.MustReadAll(res.Body)), "", " ")
|
||||
}
|
||||
out, _ := json.MarshalIndent(err, "", " ")
|
||||
fmt.Printf("%s\n\nAn error occurred: %+v\nbody: %s\n", out, err, body)
|
||||
os.Exit(1)
|
||||
}
|
||||
66
examples/go/pkg/resources.go
Normal file
66
examples/go/pkg/resources.go
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
|
||||
ory "github.com/ory/client-go"
|
||||
)
|
||||
|
||||
func RandomCredentials() (email, password string) {
|
||||
email = "dev+" + uuid.Must(uuid.NewV4()).String() + "@ory.sh"
|
||||
password = strings.ReplaceAll(uuid.Must(uuid.NewV4()).String(), "-", "")
|
||||
return
|
||||
}
|
||||
|
||||
// CreateIdentityWithSession creates an identity and an Ory Session Token for it.
|
||||
func CreateIdentityWithSession(c *ory.APIClient, email, password string) (*ory.Session, string) {
|
||||
ctx := context.Background()
|
||||
|
||||
if email == "" {
|
||||
email, _ = RandomCredentials()
|
||||
}
|
||||
|
||||
if password == "" {
|
||||
_, password = RandomCredentials()
|
||||
}
|
||||
|
||||
// Initialize a registration flow
|
||||
flow, _, err := c.FrontendAPI.CreateNativeRegistrationFlow(ctx).Execute()
|
||||
ExitOnError(err)
|
||||
|
||||
// Submit the registration flow
|
||||
result, res, err := c.FrontendAPI.UpdateRegistrationFlow(ctx).Flow(flow.Id).UpdateRegistrationFlowBody(
|
||||
ory.UpdateRegistrationFlowWithPasswordMethodAsUpdateRegistrationFlowBody(&ory.UpdateRegistrationFlowWithPasswordMethod{
|
||||
Method: "password",
|
||||
Password: password,
|
||||
Traits: map[string]interface{}{"email": email},
|
||||
}),
|
||||
).Execute()
|
||||
SDKExitOnError(err, res)
|
||||
|
||||
if result.Session == nil {
|
||||
log.Fatalf("The server is expected to create sessions for new registrations.")
|
||||
}
|
||||
|
||||
return result.Session, *result.SessionToken
|
||||
}
|
||||
|
||||
func CreateIdentity(c *ory.APIClient) *ory.Identity {
|
||||
ctx := context.Background()
|
||||
|
||||
email, _ := RandomCredentials()
|
||||
identity, _, err := c.IdentityAPI.CreateIdentity(ctx).CreateIdentityBody(ory.CreateIdentityBody{
|
||||
SchemaId: "default",
|
||||
Traits: map[string]interface{}{
|
||||
"email": email,
|
||||
}}).Execute()
|
||||
ExitOnError(err)
|
||||
return identity
|
||||
}
|
||||
36
examples/go/pkg/stub/identity.schema.json
Normal file
36
examples/go/pkg/stub/identity.schema.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"$id": "identity.schema.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Person",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"traits": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string",
|
||||
"format": "email",
|
||||
"title": "E-Mail",
|
||||
"minLength": 3,
|
||||
"ory.sh/kratos": {
|
||||
"credentials": {
|
||||
"password": {
|
||||
"identifier": true
|
||||
}
|
||||
},
|
||||
"verification": {
|
||||
"via": "email"
|
||||
},
|
||||
"recovery": {
|
||||
"via": "email"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"email"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
87
examples/go/pkg/stub/kratos.yaml
Normal file
87
examples/go/pkg/stub/kratos.yaml
Normal file
@@ -0,0 +1,87 @@
|
||||
version: v0.6.3-alpha.1
|
||||
|
||||
dsn: memory
|
||||
|
||||
serve:
|
||||
public:
|
||||
cors:
|
||||
enabled: true
|
||||
|
||||
selfservice:
|
||||
default_browser_return_url: http://127.0.0.1:4455/
|
||||
allowed_return_urls:
|
||||
- http://127.0.0.1:4455
|
||||
|
||||
methods:
|
||||
password:
|
||||
enabled: true
|
||||
link:
|
||||
enabled: true
|
||||
|
||||
flows:
|
||||
error:
|
||||
ui_url: http://127.0.0.1:4455/error
|
||||
|
||||
settings:
|
||||
ui_url: http://127.0.0.1:4455/settings
|
||||
privileged_session_max_age: 15m
|
||||
|
||||
recovery:
|
||||
enabled: true
|
||||
ui_url: http://127.0.0.1:4455/recovery
|
||||
use: link
|
||||
|
||||
verification:
|
||||
enabled: true
|
||||
ui_url: http://127.0.0.1:4455/verify
|
||||
use: link
|
||||
after:
|
||||
default_browser_return_url: http://127.0.0.1:4455/
|
||||
|
||||
logout:
|
||||
after:
|
||||
default_browser_return_url: http://127.0.0.1:4455/auth/login
|
||||
|
||||
login:
|
||||
ui_url: http://127.0.0.1:4455/auth/login
|
||||
lifespan: 10m
|
||||
|
||||
registration:
|
||||
lifespan: 10m
|
||||
ui_url: http://127.0.0.1:4455/auth/registration
|
||||
after:
|
||||
password:
|
||||
hooks:
|
||||
- hook: session
|
||||
|
||||
log:
|
||||
level: debug
|
||||
format: text
|
||||
leak_sensitive_values: true
|
||||
|
||||
secrets:
|
||||
cookie:
|
||||
- PLEASE-CHANGE-ME-I-AM-VERY-INSECURE
|
||||
cipher:
|
||||
- 32-LONG-SECRET-NOT-SECURE-AT-ALL
|
||||
|
||||
ciphers:
|
||||
algorithm: xchacha20-poly1305
|
||||
|
||||
hashers:
|
||||
argon2:
|
||||
parallelism: 1
|
||||
memory: 128MB
|
||||
iterations: 2
|
||||
salt_length: 16
|
||||
key_length: 16
|
||||
|
||||
identity:
|
||||
default_schema_id: default
|
||||
schemas:
|
||||
- id: default
|
||||
url: file://../../pkg/stub/identity.schema.json
|
||||
|
||||
courier:
|
||||
smtp:
|
||||
connection_uri: smtps://test:test@mailslurper:1025/?skip_ssl_verify=true
|
||||
Reference in New Issue
Block a user