From 0ca850cb0b1d9532292e43fc86d6b955eeea16bf Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Fri, 27 Oct 2023 21:40:17 +0530 Subject: [PATCH] Add support for email & phone number login / signup --- examples/client.go | 5 +++++ examples/deactivate_account.go | 2 +- examples/get_profile.go | 2 +- examples/get_session.go | 2 +- examples/login.go | 2 +- examples/logout.go | 2 +- examples/signup.go | 3 +-- examples/update_profile.go | 2 +- examples/validate_jwt_token.go | 2 +- examples/validate_session.go | 2 +- login.go | 9 +++++---- signup.go | 2 +- 12 files changed, 20 insertions(+), 15 deletions(-) diff --git a/examples/client.go b/examples/client.go index 772516e..5498901 100644 --- a/examples/client.go +++ b/examples/client.go @@ -6,3 +6,8 @@ const ( // Authorizer server endpoint AuthorizerURL = "http://localhost:8080" ) + +var ( + // Test email + TestEmail = "test@yopmail.com" +) diff --git a/examples/deactivate_account.go b/examples/deactivate_account.go index 68d2dc4..57a769c 100644 --- a/examples/deactivate_account.go +++ b/examples/deactivate_account.go @@ -14,7 +14,7 @@ func DeactivateAccountExample() { } loginRes, err := c.Login(&authorizer.LoginInput{ - Email: "test@yopmail.com", + Email: &TestEmail, Password: "Abc@123", }) if err != nil { diff --git a/examples/get_profile.go b/examples/get_profile.go index b15e1ab..ef012cf 100644 --- a/examples/get_profile.go +++ b/examples/get_profile.go @@ -14,7 +14,7 @@ func GetProfileExample() { } loginRes, err := c.Login(&authorizer.LoginInput{ - Email: "test@yopmail.com", + Email: &TestEmail, Password: "Abc@123", }) if err != nil { diff --git a/examples/get_session.go b/examples/get_session.go index 887f661..4bab39c 100644 --- a/examples/get_session.go +++ b/examples/get_session.go @@ -14,7 +14,7 @@ func GetSessionExample() { } loginRes, err := c.Login(&authorizer.LoginInput{ - Email: "test@yopmail.com", + Email: &TestEmail, Password: "Abc@123", }) if err != nil { diff --git a/examples/login.go b/examples/login.go index 140a0a2..1dce337 100644 --- a/examples/login.go +++ b/examples/login.go @@ -14,7 +14,7 @@ func LoginExample() { } res, err := c.Login(&authorizer.LoginInput{ - Email: "test@yopmail.com", + Email: &TestEmail, Password: "Abc@123", }) if err != nil { diff --git a/examples/logout.go b/examples/logout.go index 3dcefb5..7947e98 100644 --- a/examples/logout.go +++ b/examples/logout.go @@ -14,7 +14,7 @@ func LogoutExample() { } loginRes, err := c.Login(&authorizer.LoginInput{ - Email: "test@yopmail.com", + Email: &TestEmail, Password: "Abc@123", }) if err != nil { diff --git a/examples/signup.go b/examples/signup.go index 077b14c..140240d 100644 --- a/examples/signup.go +++ b/examples/signup.go @@ -2,7 +2,6 @@ package examples import ( "fmt" - "time" "github.com/authorizerdev/authorizer-go" ) @@ -15,7 +14,7 @@ func SignUpExample() { } res, err := c.SignUp(&authorizer.SignUpInput{ - Email: fmt.Sprintf("test.%d@yopmail.com", time.Now().Unix()), + Email: &TestEmail, Password: "Abc@123", ConfirmPassword: "Abc@123", }) diff --git a/examples/update_profile.go b/examples/update_profile.go index a105bf8..c7c7ea7 100644 --- a/examples/update_profile.go +++ b/examples/update_profile.go @@ -14,7 +14,7 @@ func UpdateProfileExample() { } loginRes, err := c.Login(&authorizer.LoginInput{ - Email: "test@yopmail.com", + Email: &TestEmail, Password: "Abc@123", }) if err != nil { diff --git a/examples/validate_jwt_token.go b/examples/validate_jwt_token.go index c2a2670..304ab89 100644 --- a/examples/validate_jwt_token.go +++ b/examples/validate_jwt_token.go @@ -14,7 +14,7 @@ func ValidateJWTTokenExample() { } loginRes, err := c.Login(&authorizer.LoginInput{ - Email: "test@yopmail.com", + Email: &TestEmail, Password: "Abc@123", }) if err != nil { diff --git a/examples/validate_session.go b/examples/validate_session.go index b7b3139..3bed4ad 100644 --- a/examples/validate_session.go +++ b/examples/validate_session.go @@ -13,7 +13,7 @@ func ValidateSessionExample() { panic(err) } _, err = c.Login(&authorizer.LoginInput{ - Email: "test@yopmail.com", + Email: &TestEmail, Password: "Abc@123", }) if err != nil { diff --git a/login.go b/login.go index b8b8b14..d6fa2c3 100644 --- a/login.go +++ b/login.go @@ -7,10 +7,11 @@ import ( // LoginInput defines attributes for login request type LoginInput struct { - Email string `json:"email"` - Password string `json:"password"` - Roles []*string `json:"roles,omitempty"` - Scope []*string `json:"scope,omitempty"` + Email *string `json:"email,omitempty"` + PhoneNumber *string `json:"phone_number,omitempty"` + Password string `json:"password"` + Roles []*string `json:"roles,omitempty"` + Scope []*string `json:"scope,omitempty"` } // Login is method attached to AuthorizerClient. diff --git a/signup.go b/signup.go index 62f6fa6..a49a7ae 100644 --- a/signup.go +++ b/signup.go @@ -7,7 +7,7 @@ import ( // SignUpInput defines attributes for signup request type SignUpInput struct { - Email string `json:"email"` + Email *string `json:"email,omitempty"` Password string `json:"password"` ConfirmPassword string `json:"confirm_password"` GivenName *string `json:"given_name,omitempty"`