Remove stream from SendMagicLink (#320)

* add two rpcs to User service:
	- Passwordless: endpoint that receives an email, topic and an optional message
	- PasswordlessML: endpoint that receives token and topic via MagicLink.

* Proposal to add Passwordless login feature to the endpoint user.

* remove currency run check

* Commit from GitHub Actions (Publish APIs & Clients)

* Create downstream.yml

* Commit from GitHub Actions (Publish APIs & Clients)

* update todo

* Commit from GitHub Actions (Publish APIs & Clients)

* Update publish.yml

* Commit from GitHub Actions (Publish APIs & Clients)

* Update publish.yml

* Commit from GitHub Actions (Publish APIs & Clients)

* Update and rename publish.yml to generate.yml

* Update generate.yml

* Commit from GitHub Actions (Generate Clients & Examples)

* Commit from GitHub Actions (Generate Clients & Examples)

* add comments

* Commit from GitHub Actions (Generate Clients & Examples)

* move otp to auth category

* charge for user verification

* Commit from GitHub Actions (Generate Clients & Examples)

* Update user.proto

* Commit from GitHub Actions (Generate Clients & Examples)

* Commit from GitHub Actions (Generate Clients & Examples)

* Change js client git repo url (#249)

* Commit from GitHub Actions (Generate Clients & Examples)

* use tableName func for Count

* Commit from GitHub Actions (Generate Clients & Examples)

* update notes example

* Commit from GitHub Actions (Generate Clients & Examples)

* Update .gitignore

* Update .gitignore

* Commit from GitHub Actions (Generate Clients & Examples)

* add new endpoints SendMagicLink and VerifyToken to M3O user serivce

Signed-off-by: Daniel Joudat <danieljoudat@gmail.com>

* remove stream from SendMagicLink

Signed-off-by: Daniel Joudat <danieljoudat@gmail.com>

* fix user/examples.json

Signed-off-by: Daniel Joudat <danieljoudat@gmail.com>

* fix typo in user.proto sessino -> session | add dumpy session in user/examples.json

Signed-off-by: Daniel Joudat <danieljoudat@gmail.com>

Co-authored-by: Asim Aslam <asim@aslam.me>
Co-authored-by: asim <asim@users.noreply.github.com>
Co-authored-by: Janos Dobronszki <dobronszki@gmail.com>
Co-authored-by: crufter <crufter@users.noreply.github.com>
This commit is contained in:
Daniel Joudat
2021-12-13 16:47:25 +03:00
committed by GitHub
parent 28fb141819
commit 2b24aba3c3
6 changed files with 75 additions and 218 deletions

View File

@@ -467,15 +467,11 @@ func (domain *Domain) List(ctx context.Context, o, l int32) ([]*user.Account, er
return ret, nil
}
func (domain *Domain) CacheToken(ctx context.Context, token, id, email string, ttl int) error {
obj := &tokenObject{
Id: id,
Email: email,
}
func (domain *Domain) CacheToken(ctx context.Context, token, email string, ttl int) error {
expires := time.Now().Add(time.Duration(ttl) * time.Second)
err := cache.Context(ctx).Set(token, obj, expires)
err := cache.Context(ctx).Set(token, email, expires)
return err
}
@@ -495,28 +491,23 @@ func (domain *Domain) SendMLE(fromName, toAddress, toUsername, subject, textCont
return err
}
func (domain *Domain) CacheReadToken(ctx context.Context, token string) (string, string, error) {
func (domain *Domain) CacheReadToken(ctx context.Context, token string) (string, error) {
if token == "" {
return "", "", errors.New("token empty")
return "", errors.New("token empty")
}
var obj tokenObject
var email string
expires, err := cache.Context(ctx).Get(token, obj)
expires, err := cache.Context(ctx).Get(token, email)
if err == cache.ErrNotFound {
return "", "", errors.New("token not found")
return "", errors.New("token not found")
} else if time.Until(expires).Seconds() < 0 {
return "", "", errors.New("token expired")
return "", errors.New("token expired")
} else if err != nil {
return "", "", microerr.InternalServerError("CacheReadToken", err.Error())
return "", microerr.InternalServerError("CacheReadToken", err.Error())
}
return obj.Id, obj.Email, nil
}
type tokenObject struct {
Id string
Email string
return email, nil
}

View File

@@ -239,14 +239,7 @@
"address": "www.example.com",
"endpoint": "verifytoken"
},
"response": {
"session": {
"id": "df91a612-5b24-4634-99ff-240220ab8f55",
"created": "1623677579",
"expires": "1623699579",
"userId": "8b98acbe-0b6a-4d66-a414-5ffbf666786f"
}
}
"response": {}
}
],
"verifyToken": [
@@ -257,8 +250,14 @@
"token": "EdsUiidouJJJLldjlloofUiorkojflsWWdld"
},
"response": {
"is_valid": false,
"message": ""
"is_valid": true,
"message": "",
"session": {
"id": "df91a612-5b24-4634-99ff-240220ab8f55",
"created": "1623677579",
"expires": "1623699579",
"userId": "8b98acbe-0b6a-4d66-a414-5ffbf666786f"
}
}
}
]

View File

@@ -4,20 +4,15 @@ import (
goctx "context"
"crypto/rand"
"encoding/base64"
"encoding/json"
"fmt"
"path"
"regexp"
"strings"
"time"
"github.com/asim/mq/broker"
"github.com/google/uuid"
"github.com/micro/micro/v3/service/errors"
"github.com/micro/micro/v3/service/logger"
db "github.com/micro/services/db/proto"
otp "github.com/micro/services/otp/proto"
"github.com/micro/services/pkg/tenant"
"github.com/micro/services/user/domain"
pb "github.com/micro/services/user/proto"
"golang.org/x/crypto/bcrypt"
@@ -401,7 +396,7 @@ func (s *User) List(ctx goctx.Context, request *pb.ListRequest, response *pb.Lis
return nil
}
func (s *User) SendMagicLink(ctx context.Context, req *pb.SendMagicLinkRequest, stream pb.User_SendMagicLinkStream) error {
func (s *User) SendMagicLink(ctx context.Context, req *pb.SendMagicLinkRequest, rsp *pb.SendMagicLinkResponse) error {
// check if the email has the correct format
if !emailFormat.MatchString(req.Email) {
return errors.BadRequest("SendMagicLink.email-format-check", "email has wrong format")
@@ -421,11 +416,8 @@ func (s *User) SendMagicLink(ctx context.Context, req *pb.SendMagicLinkRequest,
// set ttl to 60 seconds
ttl := 60
// uuid part of the topic
topic := uuid.New().String()
// save token, so we can retrieve it later
err = s.domain.CacheToken(ctx, token, topic, req.Email, ttl)
err = s.domain.CacheToken(ctx, token, req.Email, ttl)
if err != nil {
return errors.BadRequest("SendMagicLink.cacheToken", "Oooops something went wrong")
}
@@ -436,39 +428,6 @@ func (s *User) SendMagicLink(ctx context.Context, req *pb.SendMagicLinkRequest,
return errors.BadRequest("SendMagicLink.sendEmail", "Oooops something went wrong")
}
// subscribe to the topic
id, ok := tenant.FromContext(ctx)
if !ok {
id = "default"
}
// create tenant based topics
topic = path.Join("stream", id, topic)
logger.Infof("Tenant %v subscribing to %v\n", id, topic)
sub, err := broker.Subscribe(topic)
if err != nil {
return errors.InternalServerError("SendMagicLink.subscribe", "failed to subscribe to topic")
}
defer broker.Unsubscribe(topic, sub)
// range over the messages until the subscriber is closed
for msg := range sub {
// unmarshal the message into a struct
s := &pb.Session{}
err = json.Unmarshal(msg, s)
if err != nil {
return errors.InternalServerError("SendMgicLink.unmarshal", "faild to unmarshal the message")
}
if err := stream.Send(&pb.SendMagicLinkResponse{
Session: s,
}); err != nil {
return err
}
}
return nil
}
@@ -477,7 +436,7 @@ func (s *User) VerifyToken(ctx context.Context, req *pb.VerifyTokenRequest, rsp
token := req.Token
// check if token is valid
topic, email, err := s.domain.CacheReadToken(ctx, token)
email, err := s.domain.CacheReadToken(ctx, token)
if err.Error() == "token not found" {
rsp.IsValid = false
rsp.Message = err.Error()
@@ -491,12 +450,16 @@ func (s *User) VerifyToken(ctx context.Context, req *pb.VerifyTokenRequest, rsp
rsp.Message = err.Error()
return nil
} else if err != nil {
rsp.IsValid = false
rsp.Message = err.Error()
return errors.BadRequest("VerifyToken.CacheReadToken", err.Error())
}
// save session
accounts, err := s.domain.Search(ctx, "", email)
if err != nil {
rsp.IsValid = false
rsp.Message = "account not found"
return err
}
if len(accounts) == 0 {
@@ -513,32 +476,13 @@ func (s *User) VerifyToken(ctx context.Context, req *pb.VerifyTokenRequest, rsp
}
if err := s.domain.CreateSession(ctx, sess); err != nil {
rsp.IsValid = false
rsp.Message = "Creation of a new session has failed"
return errors.InternalServerError("VerifyToken.createSession", err.Error())
}
// publish a message which holds the session value.
// get the tenant
id, ok := tenant.FromContext(ctx)
if !ok {
id = "default"
}
// create tenant based topics
topic = path.Join("stream", id, topic)
// marshal the data
b, _ := json.Marshal(sess)
logger.Infof("Tenant %v publishing to %v\n", id, topic)
// publish the message
err = broker.Publish(topic, b)
if err != nil {
return errors.InternalServerError("VerifyToken.publish", "Ooops something went wrong, please try again")
}
rsp.IsValid = true
rsp.Message = ""
rsp.Session = sess
return nil
}

View File

@@ -1728,8 +1728,6 @@ type SendMagicLinkResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Session *Session `protobuf:"bytes,1,opt,name=session,proto3" json:"session,omitempty"`
}
func (x *SendMagicLinkResponse) Reset() {
@@ -1764,13 +1762,6 @@ func (*SendMagicLinkResponse) Descriptor() ([]byte, []int) {
return file_proto_user_proto_rawDescGZIP(), []int{29}
}
func (x *SendMagicLinkResponse) GetSession() *Session {
if x != nil {
return x.Session
}
return nil
}
// Check whether the token attached to MagicLink is valid or not.
// Ideally, you need to call this endpoint from your http request
// handler that handles the endpoint which is specified in the
@@ -1827,8 +1818,9 @@ type VerifyTokenResponse struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
IsValid bool `protobuf:"varint,1,opt,name=is_valid,json=isValid,proto3" json:"is_valid,omitempty"`
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
IsValid bool `protobuf:"varint,1,opt,name=is_valid,json=isValid,proto3" json:"is_valid,omitempty"`
Session *Session `protobuf:"bytes,2,opt,name=session,proto3" json:"session,omitempty"`
Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"`
}
func (x *VerifyTokenResponse) Reset() {
@@ -1870,6 +1862,13 @@ func (x *VerifyTokenResponse) GetIsValid() bool {
return false
}
func (x *VerifyTokenResponse) GetSession() *Session {
if x != nil {
return x.Session
}
return nil
}
func (x *VerifyTokenResponse) GetMessage() string {
if x != nil {
return x.Message
@@ -2046,19 +2045,19 @@ var file_proto_user_proto_rawDesc = []byte{
0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09,
0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x6e, 0x64,
0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x65, 0x6e, 0x64,
0x70, 0x6f, 0x69, 0x6e, 0x74, 0x22, 0x40, 0x0a, 0x15, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x61, 0x67,
0x69, 0x63, 0x4c, 0x69, 0x6e, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27,
0x0a, 0x07, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x0d, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x07,
0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x2a, 0x0a, 0x12, 0x56, 0x65, 0x72, 0x69, 0x66,
0x79, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a,
0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f,
0x6b, 0x65, 0x6e, 0x22, 0x4a, 0x0a, 0x13, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x54, 0x6f, 0x6b,
0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73,
0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73,
0x56, 0x61, 0x6c, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32,
0xfe, 0x07, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x35, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61,
0x70, 0x6f, 0x69, 0x6e, 0x74, 0x22, 0x17, 0x0a, 0x15, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x61, 0x67,
0x69, 0x63, 0x4c, 0x69, 0x6e, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2a,
0x0a, 0x12, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x73, 0x0a, 0x13, 0x56, 0x65,
0x72, 0x69, 0x66, 0x79, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x18, 0x01, 0x20,
0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x12, 0x27, 0x0a, 0x07,
0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e,
0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x73, 0x65,
0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32,
0xfc, 0x07, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x35, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61,
0x74, 0x65, 0x12, 0x13, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x43,
0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12,
@@ -2112,18 +2111,18 @@ var file_proto_user_proto_rawDesc = []byte{
0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x4c,
0x69, 0x73, 0x74, 0x12, 0x11, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x4c, 0x69,
0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4c, 0x0a, 0x0d,
0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4a, 0x0a, 0x0d,
0x53, 0x65, 0x6e, 0x64, 0x4d, 0x61, 0x67, 0x69, 0x63, 0x4c, 0x69, 0x6e, 0x6b, 0x12, 0x1a, 0x2e,
0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x61, 0x67, 0x69, 0x63, 0x4c, 0x69,
0x6e, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x75, 0x73, 0x65, 0x72,
0x2e, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x61, 0x67, 0x69, 0x63, 0x4c, 0x69, 0x6e, 0x6b, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, 0x44, 0x0a, 0x0b, 0x56, 0x65,
0x72, 0x69, 0x66, 0x79, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x2e, 0x75, 0x73, 0x65, 0x72,
0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66,
0x79, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x75, 0x73, 0x65, 0x72,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x0b, 0x56, 0x65, 0x72, 0x69,
0x66, 0x79, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x56,
0x65, 0x72, 0x69, 0x66, 0x79, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x19, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x54,
0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0e,
0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -2185,7 +2184,7 @@ var file_proto_user_proto_depIdxs = []int32{
1, // 5: user.ReadSessionResponse.session:type_name -> user.Session
1, // 6: user.LoginResponse.session:type_name -> user.Session
0, // 7: user.ListResponse.users:type_name -> user.Account
1, // 8: user.SendMagicLinkResponse.session:type_name -> user.Session
1, // 8: user.VerifyTokenResponse.session:type_name -> user.Session
2, // 9: user.User.Create:input_type -> user.CreateRequest
6, // 10: user.User.Read:input_type -> user.ReadRequest
8, // 11: user.User.Update:input_type -> user.UpdateRequest

View File

@@ -55,7 +55,7 @@ type UserService interface {
SendPasswordResetEmail(ctx context.Context, in *SendPasswordResetEmailRequest, opts ...client.CallOption) (*SendPasswordResetEmailResponse, error)
ResetPassword(ctx context.Context, in *ResetPasswordRequest, opts ...client.CallOption) (*ResetPasswordResponse, error)
List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*ListResponse, error)
SendMagicLink(ctx context.Context, in *SendMagicLinkRequest, opts ...client.CallOption) (User_SendMagicLinkService, error)
SendMagicLink(ctx context.Context, in *SendMagicLinkRequest, opts ...client.CallOption) (*SendMagicLinkResponse, error)
VerifyToken(ctx context.Context, in *VerifyTokenRequest, opts ...client.CallOption) (*VerifyTokenResponse, error)
}
@@ -201,53 +201,14 @@ func (c *userService) List(ctx context.Context, in *ListRequest, opts ...client.
return out, nil
}
func (c *userService) SendMagicLink(ctx context.Context, in *SendMagicLinkRequest, opts ...client.CallOption) (User_SendMagicLinkService, error) {
req := c.c.NewRequest(c.name, "User.SendMagicLink", &SendMagicLinkRequest{})
stream, err := c.c.Stream(ctx, req, opts...)
func (c *userService) SendMagicLink(ctx context.Context, in *SendMagicLinkRequest, opts ...client.CallOption) (*SendMagicLinkResponse, error) {
req := c.c.NewRequest(c.name, "User.SendMagicLink", in)
out := new(SendMagicLinkResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
if err := stream.Send(in); err != nil {
return nil, err
}
return &userServiceSendMagicLink{stream}, nil
}
type User_SendMagicLinkService interface {
Context() context.Context
SendMsg(interface{}) error
RecvMsg(interface{}) error
Close() error
Recv() (*SendMagicLinkResponse, error)
}
type userServiceSendMagicLink struct {
stream client.Stream
}
func (x *userServiceSendMagicLink) Close() error {
return x.stream.Close()
}
func (x *userServiceSendMagicLink) Context() context.Context {
return x.stream.Context()
}
func (x *userServiceSendMagicLink) SendMsg(m interface{}) error {
return x.stream.Send(m)
}
func (x *userServiceSendMagicLink) RecvMsg(m interface{}) error {
return x.stream.Recv(m)
}
func (x *userServiceSendMagicLink) Recv() (*SendMagicLinkResponse, error) {
m := new(SendMagicLinkResponse)
err := x.stream.Recv(m)
if err != nil {
return nil, err
}
return m, nil
return out, nil
}
func (c *userService) VerifyToken(ctx context.Context, in *VerifyTokenRequest, opts ...client.CallOption) (*VerifyTokenResponse, error) {
@@ -276,7 +237,7 @@ type UserHandler interface {
SendPasswordResetEmail(context.Context, *SendPasswordResetEmailRequest, *SendPasswordResetEmailResponse) error
ResetPassword(context.Context, *ResetPasswordRequest, *ResetPasswordResponse) error
List(context.Context, *ListRequest, *ListResponse) error
SendMagicLink(context.Context, *SendMagicLinkRequest, User_SendMagicLinkStream) error
SendMagicLink(context.Context, *SendMagicLinkRequest, *SendMagicLinkResponse) error
VerifyToken(context.Context, *VerifyTokenRequest, *VerifyTokenResponse) error
}
@@ -295,7 +256,7 @@ func RegisterUserHandler(s server.Server, hdlr UserHandler, opts ...server.Handl
SendPasswordResetEmail(ctx context.Context, in *SendPasswordResetEmailRequest, out *SendPasswordResetEmailResponse) error
ResetPassword(ctx context.Context, in *ResetPasswordRequest, out *ResetPasswordResponse) error
List(ctx context.Context, in *ListRequest, out *ListResponse) error
SendMagicLink(ctx context.Context, stream server.Stream) error
SendMagicLink(ctx context.Context, in *SendMagicLinkRequest, out *SendMagicLinkResponse) error
VerifyToken(ctx context.Context, in *VerifyTokenRequest, out *VerifyTokenResponse) error
}
type User struct {
@@ -361,44 +322,8 @@ func (h *userHandler) List(ctx context.Context, in *ListRequest, out *ListRespon
return h.UserHandler.List(ctx, in, out)
}
func (h *userHandler) SendMagicLink(ctx context.Context, stream server.Stream) error {
m := new(SendMagicLinkRequest)
if err := stream.Recv(m); err != nil {
return err
}
return h.UserHandler.SendMagicLink(ctx, m, &userSendMagicLinkStream{stream})
}
type User_SendMagicLinkStream interface {
Context() context.Context
SendMsg(interface{}) error
RecvMsg(interface{}) error
Close() error
Send(*SendMagicLinkResponse) error
}
type userSendMagicLinkStream struct {
stream server.Stream
}
func (x *userSendMagicLinkStream) Close() error {
return x.stream.Close()
}
func (x *userSendMagicLinkStream) Context() context.Context {
return x.stream.Context()
}
func (x *userSendMagicLinkStream) SendMsg(m interface{}) error {
return x.stream.Send(m)
}
func (x *userSendMagicLinkStream) RecvMsg(m interface{}) error {
return x.stream.Recv(m)
}
func (x *userSendMagicLinkStream) Send(m *SendMagicLinkResponse) error {
return x.stream.Send(m)
func (h *userHandler) SendMagicLink(ctx context.Context, in *SendMagicLinkRequest, out *SendMagicLinkResponse) error {
return h.UserHandler.SendMagicLink(ctx, in, out)
}
func (h *userHandler) VerifyToken(ctx context.Context, in *VerifyTokenRequest, out *VerifyTokenResponse) error {

View File

@@ -18,7 +18,7 @@ service User {
rpc SendPasswordResetEmail(SendPasswordResetEmailRequest) returns (SendPasswordResetEmailResponse) {}
rpc ResetPassword(ResetPasswordRequest) returns (ResetPasswordResponse) {}
rpc List(ListRequest) returns(ListResponse) {}
rpc SendMagicLink(SendMagicLinkRequest) returns (stream SendMagicLinkResponse) {}
rpc SendMagicLink(SendMagicLinkRequest) returns (SendMagicLinkResponse) {}
rpc VerifyToken(VerifyTokenRequest) returns (VerifyTokenResponse) {}
}
@@ -258,9 +258,7 @@ message SendMagicLinkRequest {
string endpoint = 6;
}
message SendMagicLinkResponse {
Session session = 1;
}
message SendMagicLinkResponse {}
// Check whether the token attached to MagicLink is valid or not.
// Ideally, you need to call this endpoint from your http request
@@ -272,5 +270,6 @@ message VerifyTokenRequest {
message VerifyTokenResponse {
bool is_valid = 1;
string message = 2;
Session session = 2;
string message = 3;
}