-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use sqlite
- Loading branch information
Nicolas Choquet
committed
Mar 17, 2024
1 parent
6c6d977
commit d2cff07
Showing
37 changed files
with
1,309 additions
and
211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.idea/ | ||
.dist/ | ||
.dist/ | ||
|
||
file-system-service-oauth.sqlite |
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,17 @@ | ||
package actions | ||
|
||
import ( | ||
"filesystem_service/auth" | ||
"filesystem_service/flags" | ||
) | ||
|
||
func Exec() bool { | ||
fl := flags.GetFlags() | ||
|
||
if fl.IsGenerateSignature() { | ||
auth.GenerateSignatureTokenAction() | ||
return true | ||
} | ||
|
||
return false | ||
} |
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,23 @@ | ||
package arrays | ||
|
||
func Map[T, U any](ts []T, f func(T) U) []U { | ||
us := make([]U, len(ts)) | ||
for i := range ts { | ||
us[i] = f(ts[i]) | ||
} | ||
return us | ||
} | ||
|
||
func Filter[T any](ts []T, f func(T) bool) []T { | ||
us := []T{} | ||
for i := range ts { | ||
if pass := f(ts[i]); pass { | ||
us = append(us, ts[i]) | ||
} | ||
} | ||
return us | ||
} | ||
|
||
func Generate[T any](length int) []T { | ||
return make([]T, length) | ||
} |
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,50 @@ | ||
package auth | ||
|
||
import ( | ||
"filesystem_service/customHttp" | ||
"filesystem_service/data" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func CheckToken(request *http.Request) (bool, error) { | ||
signature := request.Header.Get("Signature-Token") | ||
token := strings.Replace(request.Header.Get("Authorization"), "Bearer ", "", 1) | ||
|
||
if token == "" || signature == "" { | ||
return false, fmt.Errorf("you are not authorized") | ||
} | ||
|
||
ip, err := customHttp.GetUserIp(request) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
db, err := data.InitDatabase() | ||
defer db.Close() | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
results, err := db.Query(fmt.Sprintf( | ||
"SELECT * FROM tokens WHERE IP=\"%v\" AND active=TRUE AND type=\"classic\" AND token=\"%s\" AND signature=\"%s\"", | ||
ip, token, signature, | ||
)) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
tokens, err := data.ReadRows[Token](results, func(t *Token) error { | ||
return results.Scan(&t.Id, &t.Ip, &t.Token, &t.Signature, &t.Type, &t.Active, &t.CreatedAt) | ||
}) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
if len(tokens) == 0 { | ||
return false, fmt.Errorf("invalid access token") | ||
} | ||
|
||
return true, nil | ||
} |
Oops, something went wrong.