Compare commits

...

3 Commits
0.3.0 ... 0.4.0

Author SHA1 Message Date
Lakhan Samani
1761f41691 fix: read cookieName-client if cookie with cookieName is not present 2021-12-11 06:45:15 +05:30
Lakhan Samani
00565c8717 Fix/cookie host (#76)
* fix: cookie host

* feat: add test for url utils

* fix: url test

* fix: multi domain cookie if allowed
2021-12-11 06:41:35 +05:30
Lakhan Samani
74a551ae09 Update README.md 2021-12-09 09:17:32 +05:30
6 changed files with 51 additions and 5 deletions

View File

@@ -4,4 +4,6 @@ VERSION := $(or $(VERSION),$(DEFAULT_VERSION))
cmd:
cd server && go build -ldflags "-w -X main.Version=$(VERSION)" -o '../build/server'
clean:
rm -rf build
rm -rf build
test:
cd server && go test ./...

View File

@@ -180,3 +180,9 @@ This example demonstrates how you can use [`@authorizerdev/authorizer-js`](/auth
onLoad();
</script>
```
---
### Support my work
<a href="https://www.buymeacoffee.com/lakhansamani" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

View File

@@ -40,7 +40,7 @@ func processGoogleUserInfo(code string) (db.User, error) {
// Parse and verify ID Token payload.
idToken, err := verifier.Verify(ctx, rawIDToken)
if err != nil {
return user, fmt.Errorf("unable to verify id_token:", err.Error())
return user, fmt.Errorf("unable to verify id_token: %s", err.Error())
}
// Extract custom claims

View File

@@ -11,15 +11,23 @@ func SetCookie(gc *gin.Context, token string) {
secure := true
httpOnly := true
host := GetHostName(constants.AUTHORIZER_URL)
domain := GetDomainName(constants.AUTHORIZER_URL)
if domain != "localhost" {
domain = "." + domain
}
gc.SetSameSite(http.SameSiteNoneMode)
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", host, secure, httpOnly)
gc.SetCookie(constants.COOKIE_NAME+"-client", token, 3600, "/", domain, secure, httpOnly)
}
func GetCookie(gc *gin.Context) (string, error) {
cookie, err := gc.Request.Cookie(constants.COOKIE_NAME)
if err != nil {
return "", err
cookie, err = gc.Request.Cookie(constants.COOKIE_NAME + "-client")
if err != nil {
return "", err
}
}
return cookie.Value, nil
@@ -29,8 +37,13 @@ func DeleteCookie(gc *gin.Context) {
secure := true
httpOnly := true
host := GetHostName(constants.AUTHORIZER_URL)
host := GetDomainName(constants.AUTHORIZER_URL)
domain := GetDomainName(constants.AUTHORIZER_URL)
if domain != "localhost" {
domain = "." + domain
}
gc.SetSameSite(http.SameSiteNoneMode)
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", host, secure, httpOnly)
gc.SetCookie(constants.COOKIE_NAME+"-client", "", -1, "/", domain, secure, httpOnly)
}

View File

@@ -17,7 +17,7 @@ func GetHostName(auth_url string) string {
return host
}
// function to get domain name
// GetDomainName function to get domain name
func GetDomainName(auth_url string) string {
u, err := url.Parse(auth_url)
if err != nil {

25
server/utils/urls_test.go Normal file
View File

@@ -0,0 +1,25 @@
package utils
import "testing"
func TestGetHostName(t *testing.T) {
authorizer_url := "http://test.herokuapp.com"
got := GetHostName(authorizer_url)
want := "test.herokuapp.com"
if got != want {
t.Errorf("GetHostName Test failed got %s, wanted %s", got, want)
}
}
func TestGetDomainName(t *testing.T) {
authorizer_url := "http://test.herokuapp.com"
got := GetDomainName(authorizer_url)
want := "herokuapp.com"
if got != want {
t.Errorf("GetHostName Test failed got %q, wanted %q", got, want)
}
}