-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added registration,authentication and authorization
Signed-off-by: guacamole <[email protected]>
- Loading branch information
Showing
20 changed files
with
241 additions
and
119 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 |
---|---|---|
|
@@ -19,4 +19,3 @@ func (a *auth) verifyPassword(hashedPassword, currPassword string) bool { | |
|
||
return err == 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
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,41 @@ | ||
package auth | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/labstack/echo/v4" | ||
"time" | ||
) | ||
|
||
func (a *auth) BasicAuth(username, password string) (map[string]interface{}, error) { | ||
if username == "" || password == "" { | ||
return nil, fmt.Errorf("Email/Password cannot be empty") | ||
} | ||
|
||
key := fmt.Sprintf("%s/%s", UserNameSpace, username) | ||
bz, err := a.store.Get([]byte(key)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var userFromDb User | ||
if err := json.Unmarshal(bz, &userFromDb); err != nil { | ||
return nil, err | ||
} | ||
|
||
if !a.verifyPassword(userFromDb.Password, password) { | ||
return nil, fmt.Errorf("invalid password") | ||
} | ||
|
||
tokenLife := time.Now().Add(time.Hour * 24 * 14).Unix() | ||
token, err := a.newToken(User{Username: username}, tokenLife) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return echo.Map{ | ||
"token": token, | ||
"expires_in": tokenLife, | ||
"issued_at": time.Now().Unix(), | ||
}, 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
Oops, something went wrong.