Skip to content

Commit a912d38

Browse files
authored
Merge branch 'memphisdev:master' into master
2 parents f202e12 + 69a02d2 commit a912d38

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ curl --location --request POST 'https://REST_GW_URL:4444/auth/authenticate' \
102102
"username": "root",
103103
// "connection_token": "memphis", // OS Only: In case the chosen auth method is connection_token
104104
"password": "memphis, // OS + Cloud: client-type user password
105-
"account_id": 123456789, // Cloud only
105+
"account_id": 123456789, // Cloud only, in case you don't have the ability to set this field as a body param you can add it as a query string param, for example: https://<REST-GW-ADDRESS>/auth/authenticate?accountId=123456789
106106
"token_expiry_in_minutes": 60,
107107
"refresh_token_expiry_in_minutes": 10000092
108108
}'

handlers/auth.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ func (ah AuthHandler) Authenticate(c *fiber.Ctx) error {
7575
})
7676
}
7777

78-
conn, err := Connect(body.Password, body.Username, body.ConnectionToken, int(body.AccountId))
78+
accountId := int(body.AccountId)
79+
if accountId == 0 {
80+
accId, err := c.Request().URI().QueryArgs().GetUint("accountId")
81+
if err == nil {
82+
accountId = accId
83+
}
84+
}
85+
conn, err := Connect(body.Password, body.Username, body.ConnectionToken, accountId)
7986
if err != nil {
8087
errMsg := strings.ToLower(err.Error())
8188
if strings.Contains(errMsg, ErrorMsgAuthorizationViolation) || strings.Contains(errMsg, "token") || strings.Contains(errMsg, ErrorMsgMissionAccountId) {
@@ -90,10 +97,10 @@ func (ah AuthHandler) Authenticate(c *fiber.Ctx) error {
9097
"message": "Server error",
9198
})
9299
}
93-
if body.AccountId == 0 {
94-
body.AccountId = 1
100+
if accountId == 0 {
101+
accountId = 1
95102
}
96-
token, refreshToken, tokenExpiry, refreshTokenExpiry, err := createTokens(body.TokenExpiryMins, body.RefreshTokenExpiryMins, body.Username, int(body.AccountId), body.Password, body.ConnectionToken)
103+
token, refreshToken, tokenExpiry, refreshTokenExpiry, err := createTokens(body.TokenExpiryMins, body.RefreshTokenExpiryMins, body.Username, accountId, body.Password, body.ConnectionToken)
97104
if err != nil {
98105
log.Errorf("Authenticate: %s", err.Error())
99106
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
@@ -102,15 +109,15 @@ func (ah AuthHandler) Authenticate(c *fiber.Ctx) error {
102109
}
103110

104111
username := strings.ToLower(body.Username)
105-
accountId := strconv.Itoa(int(body.AccountId))
106-
if ConnectionsCache[accountId] == nil {
112+
accountIdStr := strconv.Itoa(accountId)
113+
if ConnectionsCache[accountIdStr] == nil {
107114
ConnectionsCacheLock.Lock()
108-
ConnectionsCache[accountId] = make(map[string]Connection)
115+
ConnectionsCache[accountIdStr] = make(map[string]Connection)
109116
ConnectionsCacheLock.Unlock()
110117
}
111118

112119
ConnectionsCacheLock.Lock()
113-
ConnectionsCache[accountId][username] = Connection{Connection: conn, ExpirationTime: tokenExpiry}
120+
ConnectionsCache[accountIdStr][username] = Connection{Connection: conn, ExpirationTime: tokenExpiry}
114121
ConnectionsCacheLock.Unlock()
115122
return c.Status(fiber.StatusOK).JSON(fiber.Map{
116123
"jwt": token,

middlewares/auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func Authenticate(c *fiber.Ctx) error {
9191
path := strings.ToLower(string(c.Context().URI().RequestURI()))
9292
var user models.AuthSchema
9393
var err error
94+
path = strings.Split(path, "?")[0]
9495
if isAuthNeeded(path) {
9596
headers := c.GetReqHeaders()
9697
tokenString, err := extractToken(headers["Authorization"])

0 commit comments

Comments
 (0)