Commit b291ac8c49a98a8c273e85fcc4000db6348a4d1f
1 parent
25e0015504
Exists in
master
and in
1 other branch
clened up
Showing
3 changed files
with
7 additions
and
17 deletions
Show diff stats
auth_utility.go
1 | 1 | package restutility |
2 | 2 | |
3 | 3 | import ( |
4 | -// "fmt" | |
5 | 4 | "errors" |
6 | -// "os" | |
7 | 5 | "time" |
8 | 6 | "crypto/sha256" |
9 | 7 | "crypto/rand" |
10 | 8 | "encoding/hex" |
11 | 9 | "strings" |
12 | 10 | "github.com/dgrijalva/jwt-go" |
13 | -// "github.com/SermoDigital/jose/jwt" | |
14 | 11 | ) |
15 | 12 | |
16 | 13 | const OneDay = time.Hour*24 |
... | ... | @@ -34,7 +31,7 @@ type CredentialsStruct struct { |
34 | 31 | Password string `json:"password"` |
35 | 32 | } |
36 | 33 | |
37 | -func generateSalt() (string, error) { | |
34 | +func GenerateSalt() (string, error) { | |
38 | 35 | salt := "" |
39 | 36 | |
40 | 37 | rawsalt := make([]byte, saltSize) |
... | ... | @@ -46,13 +43,13 @@ func generateSalt() (string, error) { |
46 | 43 | return salt, nil |
47 | 44 | } |
48 | 45 | |
49 | -func hashMessage(message string, presalt string) (string, string, error) { | |
46 | +func HashMessage(message string, presalt string) (string, string, error) { | |
50 | 47 | hash, salt := "", "" |
51 | 48 | var err error |
52 | 49 | |
53 | 50 | // chech if message is presalted |
54 | 51 | if presalt == "" { |
55 | - salt, err = generateSalt() | |
52 | + salt, err = GenerateSalt() | |
56 | 53 | if err != nil { |
57 | 54 | return "", "", err |
58 | 55 | } |
... | ... | @@ -78,7 +75,7 @@ func hashMessage(message string, presalt string) (string, string, error) { |
78 | 75 | return hash, salt, nil |
79 | 76 | } |
80 | 77 | |
81 | -func issueAPIToken(username, role string) (Token, error) { | |
78 | +func IssueAPIToken(username, role string) (Token, error) { | |
82 | 79 | var apiToken Token |
83 | 80 | var err error |
84 | 81 | |
... | ... | @@ -103,7 +100,7 @@ func issueAPIToken(username, role string) (Token, error) { |
103 | 100 | return apiToken, nil |
104 | 101 | } |
105 | 102 | |
106 | -func refreshAPIToken(tokenString string) (Token, error) { | |
103 | +func RefreshAPIToken(tokenString string) (Token, error) { | |
107 | 104 | var newToken Token |
108 | 105 | tokenString = strings.TrimPrefix(tokenString, "Bearer ") |
109 | 106 | token, err := parseTokenFunc(tokenString) |
... | ... | @@ -128,7 +125,7 @@ func refreshAPIToken(tokenString string) (Token, error) { |
128 | 125 | return newToken, nil |
129 | 126 | } |
130 | 127 | |
131 | -func parseAPIToken(tokenString string) (*TokenClaims, error) { | |
128 | +func ParseAPIToken(tokenString string) (*TokenClaims, error) { | |
132 | 129 | if ok := strings.HasPrefix(tokenString, "Bearer"); ok { |
133 | 130 | tokenString = strings.TrimPrefix(tokenString, "Bearer ") |
134 | 131 | } else { |
... | ... | @@ -157,8 +154,3 @@ func parseTokenFunc(tokenString string) (*jwt.Token, error) { |
157 | 154 | ) |
158 | 155 | return token, err |
159 | 156 | } |
160 | - | |
161 | -func authMinRegReq(uname, pword string) (bool, error) { | |
162 | - return true, nil | |
163 | -} | |
164 | - | ... | ... |
format_utility.go