-
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.
feat(auth): Move /login, /auth and /auth/refresh route to auth MS (#24)
Remove /login from user MS Add /login in auth MS Add kafka communication between the two MS for login Add documentation generation to auth MS Remove /auth/refresh from user MS Add /auth/refresh in auth MS Add kafka communication between the two MS for refresh token Remove /auth from user MS Add /auth in auth MS
- Loading branch information
1 parent
7d3a9b4
commit 5c7d0cb
Showing
68 changed files
with
1,646 additions
and
1,127 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,5 @@ | ||
install_swagger: | ||
go get -u github.com/go-swagger/go-swagger/cmd/swagger | ||
|
||
swagger: | ||
swagger generate spec -o ./swagger.yml -i swagger-auth.yml --scan-models |
This file was deleted.
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,35 @@ | ||
package data | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
// KafkaUserLoginMessage is the JSON struct sent to the user MS using the kafka topic `login`. | ||
type KafkaUserLoginMessage struct { | ||
Data KafkaUserLoginData `json:"data"` | ||
} | ||
|
||
// KafkaUserLoginData contain the data to be sent to the user MS using the kafka topic `login`. | ||
type KafkaUserLoginData struct { | ||
Login string `json:"login"` | ||
Password string `json:"password"` | ||
} | ||
|
||
// CreateLoginMessage return a JSON of KafkaUserLoginMessage from an UserLogin. | ||
func CreateLoginMessage(user UserLogin) ([]byte, error) { | ||
// Create message struct | ||
message := KafkaUserLoginMessage{ | ||
Data: KafkaUserLoginData{ | ||
Login: user.Login, | ||
Password: user.Password, | ||
}, | ||
} | ||
|
||
// Marshal message | ||
messageJSON, err := json.Marshal(message) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return messageJSON, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package data | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
// KafkaUserResponseMessage is the success answer expected from the register-response and login-response topic. | ||
type KafkaUserResponseMessage struct { | ||
Data struct { | ||
Code int `json:"code"` | ||
Content KafkaUser `json:"content"` | ||
} `json:"data"` | ||
} | ||
|
||
// KafkaUser is the data send by kafka for user info. | ||
// We don't use data.User since we need to get the ID of the user that we don't want to return in the route JSON. | ||
type KafkaUser struct { | ||
ID string `json:"id"` | ||
Username string `json:"username"` | ||
Email string `json:"email"` | ||
} | ||
|
||
// UnmarshalUserResponse unmarshal the kafka message into a KafkaUserResponseMessage. | ||
func UnmarshalUserResponse(message []byte) (*KafkaUser, error) { | ||
var messageStruct KafkaUserResponseMessage | ||
if err := json.Unmarshal(message, &messageStruct); err != nil { | ||
log.Println(err) | ||
return nil, NewHTTPErrorInfo(fiber.StatusInternalServerError, err.Error()) | ||
} | ||
return &messageStruct.Data.Content, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package data | ||
|
||
// UserLogin is the body parameter given to login a new user. | ||
// swagger:model | ||
type UserLogin struct { | ||
// The email or the username of the user | ||
// required: true | ||
// example: john@provider.net | ||
Login string `json:"login" validate:"required"` | ||
// The password of the user | ||
// required: true | ||
// example: leHAiOjE1OTgzNz | ||
Password string `json:"password" validate:"required"` | ||
} |
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.