-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add more SDK methods * Add more SDK methods * client info fix * Expose credential exists method * add error data to server error
- Loading branch information
1 parent
b39519d
commit 6c76622
Showing
22 changed files
with
933 additions
and
68 deletions.
There are no files selected for viewing
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,75 @@ | ||
package emailcode | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/corbado/corbado-go/pkg/sdk/assert" | ||
"github.com/corbado/corbado-go/pkg/sdk/entity/api" | ||
"github.com/corbado/corbado-go/pkg/sdk/entity/common" | ||
"github.com/corbado/corbado-go/pkg/sdk/servererror" | ||
) | ||
|
||
type EmailCode interface { | ||
Send(ctx context.Context, req api.EmailCodeSendReq, editors ...api.RequestEditorFn) (*api.EmailCodeSendRsp, error) | ||
Validate(ctx context.Context, emailCodeID common.EmailCodeID, req api.EmailCodeValidateReq, editors ...api.RequestEditorFn) (*api.EmailCodeValidateRsp, error) | ||
Get(ctx context.Context, emailCodeID common.EmailCodeID, editors ...api.RequestEditorFn) (*api.EmailCodeGetRsp, error) | ||
} | ||
|
||
type Impl struct { | ||
client *api.ClientWithResponses | ||
} | ||
|
||
var _ EmailCode = &Impl{} | ||
|
||
// New returns new email code client | ||
func New(client *api.ClientWithResponses) (*Impl, error) { | ||
if err := assert.NotNil(client); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Impl{ | ||
client: client, | ||
}, nil | ||
} | ||
|
||
// Send sends email code email to given email address | ||
func (i *Impl) Send(ctx context.Context, req api.EmailCodeSendReq, editors ...api.RequestEditorFn) (*api.EmailCodeSendRsp, error) { | ||
res, err := i.client.EmailCodeSendWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// Validate validates email code token | ||
func (i *Impl) Validate(ctx context.Context, emailCodeID common.EmailCodeID, req api.EmailCodeValidateReq, editors ...api.RequestEditorFn) (*api.EmailCodeValidateRsp, error) { | ||
res, err := i.client.EmailCodeValidateWithResponse(ctx, emailCodeID, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// Get gets email code | ||
func (i *Impl) Get(ctx context.Context, emailCodeID common.EmailCodeID, editors ...api.RequestEditorFn) (*api.EmailCodeGetRsp, error) { | ||
res, err := i.client.EmailCodeGetWithResponse(ctx, emailCodeID, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,193 @@ | ||
package passkey | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/corbado/corbado-go/pkg/sdk/assert" | ||
"github.com/corbado/corbado-go/pkg/sdk/entity/api" | ||
"github.com/corbado/corbado-go/pkg/sdk/servererror" | ||
) | ||
|
||
type Passkey interface { | ||
RegisterStart(ctx context.Context, req api.WebAuthnRegisterStartReq, editors ...api.RequestEditorFn) (*api.WebAuthnRegisterStartRsp, error) | ||
RegisterFinish(ctx context.Context, req api.WebAuthnFinishReq, editors ...api.RequestEditorFn) (*api.WebAuthnRegisterFinishRsp, error) | ||
AuthenticateStart(ctx context.Context, req api.WebAuthnAuthenticateStartReq, editors ...api.RequestEditorFn) (*api.WebAuthnAuthenticateStartRsp, error) | ||
AuthenticateFinish(ctx context.Context, req api.WebAuthnFinishReq, editors ...api.RequestEditorFn) (*api.WebAuthnAuthenticateFinishRsp, error) | ||
MediationStart(ctx context.Context, req api.WebAuthnMediationStartReq, editors ...api.RequestEditorFn) (*api.WebAuthnMediationStartRsp, error) | ||
AssociateStart(ctx context.Context, req api.WebAuthnAssociateStartReq, editors ...api.RequestEditorFn) (*api.WebAuthnAssociateStartRsp, error) | ||
CredentialList(ctx context.Context, params *api.WebAuthnCredentialListParams, editors ...api.RequestEditorFn) (*api.WebAuthnCredentialListRsp, error) | ||
CredentialUpdate(ctx context.Context, credentialID string, req api.WebAuthnCredentialReq, editors ...api.RequestEditorFn) (*api.WebAuthnCredentialRsp, error) | ||
CredentialExists(ctx context.Context, req api.WebAuthnCredentialExistsReq, editors ...api.RequestEditorFn) (*api.WebAuthnCredentialExistsRsp, error) | ||
CredentialDelete(ctx context.Context, userID string, credentialID string, req api.EmptyReq, editors ...api.RequestEditorFn) error | ||
} | ||
|
||
type Impl struct { | ||
client *api.ClientWithResponses | ||
} | ||
|
||
var _ Passkey = &Impl{} | ||
|
||
// New returns new projects client | ||
func New(client *api.ClientWithResponses) (*Impl, error) { | ||
if err := assert.NotNil(client); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Impl{ | ||
client: client, | ||
}, nil | ||
} | ||
|
||
// CreateSecret creates an API secret | ||
func (i *Impl) CreateSecret(ctx context.Context, req api.ProjectSecretCreateReq, editors ...api.RequestEditorFn) (*api.ProjectSecretCreateRsp, error) { | ||
res, err := i.client.ProjectSecretCreateWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// RegisterStart starts registration of a user for Passkeys (Biometrics) | ||
func (i *Impl) RegisterStart(ctx context.Context, req api.WebAuthnRegisterStartReq, editors ...api.RequestEditorFn) (*api.WebAuthnRegisterStartRsp, error) { | ||
res, err := i.client.WebAuthnRegisterStartWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// RegisterFinish completes registration of a user for Passkeys (Biometrics) | ||
func (i *Impl) RegisterFinish(ctx context.Context, req api.WebAuthnFinishReq, editors ...api.RequestEditorFn) (*api.WebAuthnRegisterFinishRsp, error) { | ||
res, err := i.client.WebAuthnRegisterFinishWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// AuthenticateStart starts authentication of a user for Passkeys (Biometrics) | ||
func (i *Impl) AuthenticateStart(ctx context.Context, req api.WebAuthnAuthenticateStartReq, editors ...api.RequestEditorFn) (*api.WebAuthnAuthenticateStartRsp, error) { | ||
res, err := i.client.WebAuthnAuthenticateStartWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// AuthenticateFinish completes authentication of a user for Passkeys (Biometrics) | ||
func (i *Impl) AuthenticateFinish(ctx context.Context, req api.WebAuthnFinishReq, editors ...api.RequestEditorFn) (*api.WebAuthnAuthenticateFinishRsp, error) { | ||
res, err := i.client.WebAuthnAuthenticateFinishWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// MediationStart starts mediation for Passkeys (Biometrics) | ||
func (i *Impl) MediationStart(ctx context.Context, req api.WebAuthnMediationStartReq, editors ...api.RequestEditorFn) (*api.WebAuthnMediationStartRsp, error) { | ||
res, err := i.client.WebAuthnMediationStartWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// AssociateStart starts association token flow for Passkeys (Biometrics) | ||
func (i *Impl) AssociateStart(ctx context.Context, req api.WebAuthnAssociateStartReq, editors ...api.RequestEditorFn) (*api.WebAuthnAssociateStartRsp, error) { | ||
res, err := i.client.WebAuthnAssociateStartWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// CredentialList lists webauthn credentials users | ||
func (i *Impl) CredentialList(ctx context.Context, params *api.WebAuthnCredentialListParams, editors ...api.RequestEditorFn) (*api.WebAuthnCredentialListRsp, error) { | ||
res, err := i.client.WebAuthnCredentialListWithResponse(ctx, params, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// CredentialUpdate updates webauthn credential | ||
func (i *Impl) CredentialUpdate(ctx context.Context, credentialID string, req api.WebAuthnCredentialReq, editors ...api.RequestEditorFn) (*api.WebAuthnCredentialRsp, error) { | ||
res, err := i.client.WebAuthnCredentialUpdateWithResponse(ctx, credentialID, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// CredentialExists checks if active webauthn credential exists for provided user and device | ||
func (i *Impl) CredentialExists(ctx context.Context, req api.WebAuthnCredentialExistsReq, editors ...api.RequestEditorFn) (*api.WebAuthnCredentialExistsRsp, error) { | ||
res, err := i.client.WebAuthnCredentialExistsWithResponse(ctx, req, editors...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return nil, servererror.New(res.JSONDefault) | ||
} | ||
|
||
return res.JSON200, nil | ||
} | ||
|
||
// CredentialDelete deletes webauthn credential | ||
func (i *Impl) CredentialDelete(ctx context.Context, userID string, credentialID string, req api.EmptyReq, editors ...api.RequestEditorFn) error { | ||
res, err := i.client.WebAuthnCredentialDeleteWithResponse(ctx, userID, credentialID, req, editors...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if res.JSONDefault != nil { | ||
return servererror.New(res.JSONDefault) | ||
} | ||
|
||
return nil | ||
} |
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
Oops, something went wrong.