mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-18 08:26:38 +02:00
4ae2528cbe
* add m3o services * update readme
56 lines
1.3 KiB
Go
Executable File
56 lines
1.3 KiB
Go
Executable File
package otp
|
|
|
|
import (
|
|
"github.com/m3o/m3o-go/client"
|
|
)
|
|
|
|
func NewOtpService(token string) *OtpService {
|
|
return &OtpService{
|
|
client: client.NewClient(&client.Options{
|
|
Token: token,
|
|
}),
|
|
}
|
|
}
|
|
|
|
type OtpService struct {
|
|
client *client.Client
|
|
}
|
|
|
|
// Generate an OTP (one time pass) code
|
|
func (t *OtpService) Generate(request *GenerateRequest) (*GenerateResponse, error) {
|
|
rsp := &GenerateResponse{}
|
|
return rsp, t.client.Call("otp", "Generate", request, rsp)
|
|
}
|
|
|
|
// Validate the OTP code
|
|
func (t *OtpService) Validate(request *ValidateRequest) (*ValidateResponse, error) {
|
|
rsp := &ValidateResponse{}
|
|
return rsp, t.client.Call("otp", "Validate", request, rsp)
|
|
}
|
|
|
|
type GenerateRequest struct {
|
|
// expiration in seconds (default: 60)
|
|
Expiry int64 `json:"expiry,string"`
|
|
// unique id, email or user to generate an OTP for
|
|
Id string `json:"id"`
|
|
// number of characters (default: 6)
|
|
Size int64 `json:"size,string"`
|
|
}
|
|
|
|
type GenerateResponse struct {
|
|
// one time pass code
|
|
Code string `json:"code"`
|
|
}
|
|
|
|
type ValidateRequest struct {
|
|
// one time pass code to validate
|
|
Code string `json:"code"`
|
|
// unique id, email or user for which the code was generated
|
|
Id string `json:"id"`
|
|
}
|
|
|
|
type ValidateResponse struct {
|
|
// returns true if the code is valid for the ID
|
|
Success bool `json:"success"`
|
|
}
|