mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 17:49:09 +00:00
finish login story
This commit is contained in:
parent
a23184efd2
commit
c9cb4c95bc
34 changed files with 14564 additions and 21666 deletions
|
@ -43,6 +43,15 @@ func (g GetenvValue) StringSlice(optionalDelimiter ...string) []string {
|
|||
return strings.Split(g.value, delimiter)
|
||||
}
|
||||
|
||||
// SafeURL removes any trailing slash
|
||||
func (g GetenvValue) SafeURL() string {
|
||||
if g.value[len(g.value)-1] == '/' {
|
||||
return g.value[:len(g.value)-1]
|
||||
}
|
||||
|
||||
return g.value
|
||||
}
|
||||
|
||||
func (g GetenvValue) Bool() bool {
|
||||
lowercaseValue := strings.ToLower(g.value)
|
||||
if g.value == "1" || lowercaseValue == "true" || lowercaseValue == "yes" {
|
||||
|
|
|
@ -2,6 +2,7 @@ package common_test
|
|||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/onsi/gomega"
|
||||
|
@ -14,6 +15,8 @@ var (
|
|||
"slice": "hello,world",
|
||||
"slice_no_delim": "hello world",
|
||||
"slice_set_delim": "hello|world",
|
||||
"url": "https://google.com",
|
||||
"url_trailing": "https://google.com/",
|
||||
"number": "10005",
|
||||
"number_bad": "abc123",
|
||||
"bool": "true",
|
||||
|
@ -61,6 +64,19 @@ func TestEnvconfigStringSliceSetDelimeter(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestEnvconfigSafeURL(t *testing.T) {
|
||||
testUrl := common.Getenv("test__url").SafeURL()
|
||||
if strings.HasSuffix(testUrl, "/") {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
func TestEnvconfigSafeURLWithTrailing(t *testing.T) {
|
||||
testUrl := common.Getenv("test__url_trailing").SafeURL()
|
||||
if strings.HasSuffix(testUrl, "/") {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnvconfigNumber(t *testing.T) {
|
||||
testNum := common.Getenv("test__number").Number()
|
||||
if testNum != 10005 {
|
||||
|
|
|
@ -62,5 +62,14 @@ func Unstash(rw http.ResponseWriter, req *http.Request, defaultURL string) {
|
|||
redirectURL = cookie.Value
|
||||
}
|
||||
|
||||
unsetter := http.Cookie{
|
||||
Name: "rp_stashed_url",
|
||||
Value: "",
|
||||
MaxAge: -1,
|
||||
HttpOnly: true,
|
||||
}
|
||||
|
||||
rw.Header().Set("set-cookie", unsetter.String())
|
||||
|
||||
Bounce(rw, redirectURL)
|
||||
}
|
||||
|
|
15
src/common/faas/fingerprint.go
Normal file
15
src/common/faas/fingerprint.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package faas
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/roleypoly/roleypoly/src/common/types"
|
||||
)
|
||||
|
||||
func Fingerprint(req *http.Request) types.Fingerprint {
|
||||
return types.Fingerprint{
|
||||
UserAgent: req.UserAgent(),
|
||||
ClientIP: req.RemoteAddr,
|
||||
ForwardedFor: req.Header.Get("x-forwarded-for"),
|
||||
}
|
||||
}
|
20
src/common/types/User.go
Normal file
20
src/common/types/User.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package types
|
||||
|
||||
type DiscordUser struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Discriminator string `json:"discriminator,omitempty"`
|
||||
Avatar string `json:"avatar,omitempty"`
|
||||
Bot bool `json:"bot,omitempty"`
|
||||
}
|
||||
|
||||
type Member struct {
|
||||
GuildID string `json:"guildid,omitempty"`
|
||||
Roles []string `json:"rolesList,omitempty"`
|
||||
Nick string `json:"nick,omitempty"`
|
||||
User DiscordUser `json:"user,omitempty"`
|
||||
}
|
||||
|
||||
type RoleypolyUser struct {
|
||||
DiscordUser DiscordUser `json:"discorduser,omitempty"`
|
||||
}
|
31
src/common/types/session.go
Normal file
31
src/common/types/session.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
// CreateSessionRequest is the payload to /create-session
|
||||
type CreateSessionRequest struct {
|
||||
AccessTokenResponse AccessTokenResponse
|
||||
Fingerprint Fingerprint
|
||||
}
|
||||
|
||||
type Fingerprint struct {
|
||||
UserAgent string
|
||||
ClientIP string
|
||||
ForwardedFor string
|
||||
}
|
||||
|
||||
type CreateSessionResponse struct {
|
||||
SessionID string
|
||||
}
|
||||
|
||||
type SessionData struct {
|
||||
SessionID string
|
||||
Fingerprint Fingerprint
|
||||
AccessTokens AccessTokenResponse
|
||||
UserData UserData
|
||||
}
|
||||
|
||||
type UserData struct {
|
||||
DataExpires time.Time
|
||||
UserID string
|
||||
}
|
10
src/common/types/tokens.go
Normal file
10
src/common/types/tokens.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package types
|
||||
|
||||
// AccessTokenResponse is the response for Discord's OAuth token grant flow
|
||||
type AccessTokenResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
TokenType string `json:"token_type"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
Scope string `json:"scope"`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue