-
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.
feat: Auth tokens for client-side usage
Signed-off-by: jay-dee7 <[email protected]>
- Loading branch information
Showing
16 changed files
with
332 additions
and
9 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
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
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
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,14 @@ | ||
#!/bin/sh | ||
|
||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "johndoe", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "asta", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "yuno", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "noelle", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "mimosa", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "klaus", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "finral", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "yami", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "vangeance", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "leopold", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "vanessa", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq | ||
curl -sSL -XPOST -d '{"email": "[email protected]", "username": "charmy", "password": "Qwerty@123"}' 'http://localhost:5000/auth/signup' | jq |
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,60 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"strings" | ||
"time" | ||
|
||
"github.com/oklog/ulid/v2" | ||
) | ||
|
||
type AuthToken struct { | ||
id ulid.ULID | ||
} | ||
|
||
const ( | ||
OpenRegistryAuthTokenPrefix = "oreg_pat_" | ||
) | ||
|
||
func (at *AuthToken) String() string { | ||
return fmt.Sprintf("%s%s", OpenRegistryAuthTokenPrefix, at.id.String()) | ||
} | ||
|
||
func (at *AuthToken) Bytes() []byte { | ||
return at.id.Bytes() | ||
} | ||
|
||
func (at *AuthToken) Compare(other ulid.ULID) int { | ||
return at.id.Compare(other) | ||
} | ||
|
||
func (at *AuthToken) FromString(token string) (*AuthToken, error) { | ||
token = strings.TrimPrefix(token, OpenRegistryAuthTokenPrefix) | ||
|
||
id, err := ulid.Parse(token) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &AuthToken{id: id}, nil | ||
} | ||
|
||
func (at *AuthToken) RawString() string { | ||
return at.id.String() | ||
} | ||
|
||
func CreateNewAuthToken() (*AuthToken, error) { | ||
now := time.Now() | ||
entropy := rand.New(rand.NewSource(now.UnixNano())) | ||
ms := ulid.Timestamp(now) | ||
|
||
id, err := ulid.New(ms, entropy) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &AuthToken{ | ||
id: id, | ||
}, nil | ||
} |
Oops, something went wrong.