Stage 11: account linking & merge (email + Telegram Login Widget) (#12)
This commit was merged in pull request #12.
This commit is contained in:
@@ -22,6 +22,10 @@ import (
|
||||
// result code.
|
||||
var ErrInvalidInitData = errors.New("connector: invalid telegram init data")
|
||||
|
||||
// ErrInvalidLoginWidget is returned by ValidateLoginWidget when the connector
|
||||
// rejects the Login Widget data (a gRPC InvalidArgument).
|
||||
var ErrInvalidLoginWidget = errors.New("connector: invalid telegram login widget data")
|
||||
|
||||
// User is a validated Mini App identity.
|
||||
type User struct {
|
||||
ExternalID string
|
||||
@@ -66,6 +70,24 @@ func (c *Client) ValidateInitData(ctx context.Context, initData string) (User, e
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ValidateLoginWidget verifies Telegram Login Widget data and returns the user
|
||||
// identity, mapping a connector InvalidArgument to ErrInvalidLoginWidget. It backs
|
||||
// the link.telegram edge operation (Stage 11).
|
||||
func (c *Client) ValidateLoginWidget(ctx context.Context, data string) (User, error) {
|
||||
resp, err := c.c.ValidateLoginWidget(ctx, &telegramv1.ValidateLoginWidgetRequest{Data: data})
|
||||
if err != nil {
|
||||
if status.Code(err) == codes.InvalidArgument {
|
||||
return User{}, ErrInvalidLoginWidget
|
||||
}
|
||||
return User{}, err
|
||||
}
|
||||
return User{
|
||||
ExternalID: resp.GetExternalId(),
|
||||
Username: resp.GetUsername(),
|
||||
FirstName: resp.GetFirstName(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Notify delivers an out-of-app notification for a push event; delivered reports
|
||||
// whether a message was actually sent.
|
||||
func (c *Client) Notify(ctx context.Context, externalID, kind string, payload []byte, language string) (bool, error) {
|
||||
|
||||
Reference in New Issue
Block a user