-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* proto: minor changes to identity * rpc/auth/email: return email as Identity.Subject * rpc: implement getIdToken intent handling * proto: fix incorrect Identity JSON field names * rpc: wrap error Co-authored-by: Vojtech Vitek (golang.cz) <[email protected]> * rpc: improve variable naming --------- Co-authored-by: Vojtech Vitek (golang.cz) <[email protected]>
- Loading branch information
1 parent
882fcfb
commit d5f6f3d
Showing
10 changed files
with
236 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* eslint-disable */ | ||
// sequence-waas-authenticator v0.1.0 78c0fb43d3928a11e1a59af0f866461164f9616c | ||
// sequence-waas-authenticator v0.1.0 0162a6fb35dd49d6f4d924ebce4bceb847479f3a | ||
// -- | ||
// Code generated by [email protected] with typescript generator. DO NOT EDIT. | ||
// | ||
|
@@ -12,7 +12,7 @@ export const WebRPCVersion = "v1" | |
export const WebRPCSchemaVersion = "v0.1.0" | ||
|
||
// Schema hash generated from your RIDL schema | ||
export const WebRPCSchemaHash = "78c0fb43d3928a11e1a59af0f866461164f9616c" | ||
export const WebRPCSchemaHash = "0162a6fb35dd49d6f4d924ebce4bceb847479f3a" | ||
|
||
// | ||
// Types | ||
|
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
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
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,92 @@ | ||
package rpc_test | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/0xsequence/ethkit/ethwallet" | ||
"github.com/0xsequence/go-sequence/intents" | ||
"github.com/0xsequence/waas-authenticator/proto" | ||
"github.com/0xsequence/waas-authenticator/rpc" | ||
"github.com/lestrrat-go/jwx/v2/jwk" | ||
"github.com/lestrrat-go/jwx/v2/jwt" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRPC_SendIntent_GetIdToken(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
issuer, _, closeJWKS := issueAccessTokenAndRunJwksServer(t, func(b *jwt.Builder, s string) { | ||
b.Claim("email", "[email protected]").Claim("email_verified", true) | ||
}) | ||
defer closeJWKS() | ||
|
||
sessWallet, err := ethwallet.NewWalletFromRandomEntropy() | ||
require.NoError(t, err) | ||
signingSession := intents.NewSessionP256K1(sessWallet) | ||
|
||
svc := initRPC(t) | ||
|
||
tenant, tntData := newTenant(t, svc.Enclave, issuer) | ||
acc := newAccount(t, tenant, svc.Enclave, newOIDCIdentity(issuer), sessWallet) | ||
sess := newSession(t, tenant, svc.Enclave, issuer, signingSession) | ||
|
||
walletAddr, err := rpc.AddressForUser(context.Background(), tntData, acc.UserID) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, svc.Tenants.Add(ctx, tenant)) | ||
require.NoError(t, svc.Accounts.Put(ctx, acc)) | ||
require.NoError(t, svc.Sessions.Put(ctx, sess)) | ||
|
||
srv := httptest.NewServer(svc.Handler()) | ||
defer srv.Close() | ||
svc.Config.BaseURL = srv.URL | ||
svc.Config.Builder.BaseURL = "https://sequence.build" | ||
|
||
intentData := &intents.IntentDataGetIdToken{ | ||
Wallet: walletAddr, | ||
SessionID: sess.ID, | ||
Nonce: "NONCE", | ||
} | ||
intent := generateSignedIntent(t, intents.IntentName_getIdToken, intentData, signingSession) | ||
|
||
c := proto.NewWaasAuthenticatorClient(srv.URL, http.DefaultClient) | ||
header := make(http.Header) | ||
header.Set("X-Sequence-Project", strconv.Itoa(int(tenant.ProjectID))) | ||
ctx, err = proto.WithHTTPRequestHeaders(ctx, header) | ||
require.NoError(t, err) | ||
|
||
res, err := c.SendIntent(ctx, intent) | ||
require.NoError(t, err) | ||
assert.Equal(t, proto.IntentResponseCode_idToken, res.Code) | ||
assert.NotEmpty(t, res.Data) | ||
|
||
resData := unmarshalResponse[intents.IntentResponseIdToken](t, res.Data) | ||
|
||
jwks, err := jwk.Fetch(context.Background(), srv.URL+"/.well-known/jwks.json") | ||
require.NoError(t, err) | ||
|
||
opts := []jwt.ParseOption{ | ||
jwt.WithKeySet(jwks), | ||
jwt.WithIssuer(srv.URL), | ||
jwt.WithAudience("https://sequence.build/project/" + strconv.Itoa(int(tenant.ProjectID))), | ||
jwt.WithSubject(walletAddr), | ||
jwt.WithClaimValue("nonce", "NONCE"), | ||
jwt.WithClaimValue("email", "[email protected]"), | ||
} | ||
tok, err := jwt.Parse([]byte(resData.IdToken), opts...) | ||
require.NoError(t, err) | ||
require.NotNil(t, tok) | ||
|
||
identClaim, ok := tok.Get(srv.URL + "/identity") | ||
require.True(t, ok) | ||
identMap, ok := identClaim.(map[string]any) | ||
require.True(t, ok, "should be a map, is %+v", identClaim) | ||
assert.Equal(t, "OIDC", identMap["type"]) | ||
assert.Equal(t, issuer, identMap["iss"]) | ||
assert.Equal(t, "SUBJECT", identMap["sub"]) | ||
} |
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