Skip to content

Commit

Permalink
Implement account linking for incoming login ID #4372
Browse files Browse the repository at this point in the history
ref DEV-1233
  • Loading branch information
tung2744 authored Jun 20, 2024
2 parents bd935ac + 72d08ad commit 824c914
Show file tree
Hide file tree
Showing 80 changed files with 2,375 additions and 326 deletions.
3 changes: 3 additions & 0 deletions e2e/cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import (

"github.com/authgear/authgear-server/e2e/cmd/proxy/mockoidc"
"github.com/authgear/authgear-server/e2e/cmd/proxy/modifier"
"github.com/authgear/authgear-server/pkg/util/debug"
)

func main() {
debug.TrapSIGQUIT()

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()

Expand Down
3 changes: 2 additions & 1 deletion e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function teardown {( set -e

function tests {( set -e
echo "[ ] Run tests..."
go test ./... -v -timeout 10m -parallel 5
# Use -count 1 to disable cache. We want to run the tests without caching.
go test ./... -count 1 -v -timeout 10m -parallel 5
)}

function main {( set -e
Expand Down
8 changes: 8 additions & 0 deletions e2e/tests/account_linking/google_user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"identifier": "preferred_username",
"records": [
{
"preferred_username": "mock"
}
]
}
40 changes: 40 additions & 0 deletions e2e/tests/account_linking/google_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
INSERT INTO _auth_identity (
"id",
"app_id",
"type",
"user_id",
"created_at",
"updated_at"
) VALUES (
'{{ .AppID }}__google__',
'{{ .AppID }}',
'oauth',
(SELECT b.user_id
FROM _auth_identity_login_id a
JOIN _auth_identity b
ON a.id = b.id
WHERE a.login_id = 'mock'
AND a.app_id = '{{ .AppID }}'
LIMIT 1
),
NOW(),
NOW()
);

INSERT INTO _auth_identity_oauth (
"id",
"app_id",
"provider_type",
"provider_keys",
"provider_user_id",
"claims",
"profile"
) VALUES (
'{{ .AppID }}__google__',
'{{ .AppID }}',
'google',
'{}',
'mock',
'{"email": "[email protected]"}',
'{"email": "[email protected]"}'
);
9 changes: 9 additions & 0 deletions e2e/tests/account_linking/google_user_with_phone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"identifier": "preferred_username",
"records": [
{
"preferred_username": "mock",
"phone_number": "+85298765432"
}
]
}
69 changes: 69 additions & 0 deletions e2e/tests/account_linking/incoming_login_id_action_error.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Account linking - Incoming Login ID - action=error
authgear.yaml:
override: |
authentication:
identities:
- login_id
- oauth
identity:
login_id:
keys:
- type: email
- type: username
oauth:
providers:
- alias: google
client_id: "google"
type: google
account_linking:
login_id:
- key: email
action: error
user_profile:
pointer: "/email"
authentication_flow:
signup_flows:
- name: f1
steps:
- type: identify
one_of:
- identification: email
- identification: oauth
before:
- type: user_import
user_import: google_user.json
- type: custom_sql
custom_sql:
path: google_user.sql
steps:
- action: "create"
input: |
{
"type": "signup",
"name": "f1"
}
output:
result: |
{
"action": {
"type": "identify"
}
}
- action: input
input: |
{
"identification": "email",
"login_id": "[email protected]"
}
output:
error: |
{
"reason": "InvariantViolated",
"info": {
"cause": {
"kind": "DuplicatedIdentity"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: Account linking - Incoming Login ID - create_authenticator before it
authgear.yaml:
override: |
authentication:
identities:
- login_id
- oauth
identity:
login_id:
keys:
- type: email
- type: username
oauth:
providers:
- alias: google
client_id: "google"
type: google
account_linking:
login_id:
- key: email
action: login_and_link
user_profile:
pointer: "/email"
authentication_flow:
signup_flows:
- name: f1
steps:
- type: create_authenticator
one_of:
- authentication: primary_password
- type: identify
one_of:
- identification: email
login_flows:
- name: f1
steps:
- name: identify
type: identify
one_of:
- identification: oauth
- identification: email
steps:
- type: authenticate
one_of:
- authentication: primary_password
before:
- type: user_import
user_import: google_user.json
- type: custom_sql
custom_sql:
path: google_user.sql
steps:
- action: "create"
input: |
{
"type": "signup",
"name": "f1"
}
output:
result: |
{
"action": {
"type": "create_authenticator"
}
}
- action: input
input: |
{
"authentication": "primary_password",
"new_password": "12341234a"
}
output:
result: |
{
"action": {
"type": "identify"
}
}
- action: input
input: |
{
"identification": "email",
"login_id": "[email protected]"
}
output:
result: |
{
"action": {
"type": "identify",
"identification": "email",
"data": {
"type": "account_linking_identification_data"
}
}
}
- action: input
input: |
{
"index": 0,
"redirect_uri": "http://mock"
}
output:
result: |
{
"action": {
"type": "identify",
"identification": "oauth",
"data": {
"type": "oauth_data",
"alias": "google",
"oauth_provider_type": "google",
"oauth_authorization_url": "[[string]]"
}
}
}
- action: oauth_redirect
to: "{{ .prev.result.action.data.oauth_authorization_url }}"
redirect_uri: http://mock
output:
result: |
{
"query": "[[string]]"
}
- action: input
input: |
{
"query": "{{ .prev.result.query }}"
}
output:
result: |
{
"action": {
"type": "finished"
}
}
Loading

0 comments on commit 824c914

Please sign in to comment.