-
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.
Merge pull request #8 from go-gorf/7-jwt-login-using-aws-cognito
aws cognito
- Loading branch information
Showing
16 changed files
with
337 additions
and
179 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,19 +1,25 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider" | ||
"github.com/go-gorf/gorf" | ||
) | ||
|
||
func setup() error { | ||
err := gorf.DB.AutoMigrate(&User{}) | ||
cognitoCtx = context.Background() | ||
defaultConfig, err := config.LoadDefaultConfig(cognitoCtx, config.WithRegion(Settings.Region)) | ||
if err != nil { | ||
return err | ||
} | ||
client = cognitoidentityprovider.NewFromConfig(defaultConfig) | ||
return nil | ||
} | ||
|
||
var AuthApp = gorf.GorfBaseApp{ | ||
Name: "auth", | ||
var App = gorf.BaseApp{ | ||
Title: "Auth", | ||
Info: "Gorf Auth handler app", | ||
RouteHandler: Urls, | ||
SetUpHandler: setup, | ||
} |
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,19 @@ | ||
package auth | ||
|
||
import ( | ||
"github.com/go-gorf/gorf" | ||
) | ||
|
||
func setup() error { | ||
err := gorf.DB.AutoMigrate(&User{}) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
var AuthApp = gorf.GorfBaseApp{ | ||
Name: "auth", | ||
RouteHandler: Urls, | ||
SetUpHandler: setup, | ||
} |
File renamed without changes.
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,44 @@ | ||
module github.com/go-gorf/auth/legacy | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/gin-gonic/gin v1.9.0 | ||
github.com/go-gorf/gorf v0.0.11 | ||
github.com/go-gorf/gorf/backends/gormi v0.0.0-20230528184453-b3cb1ef2741a | ||
github.com/golang-jwt/jwt/v5 v5.0.0-rc.2 | ||
github.com/stretchr/testify v1.8.2 | ||
golang.org/x/crypto v0.7.0 | ||
gorm.io/gorm v1.25.1 | ||
) | ||
|
||
require ( | ||
github.com/bytedance/sonic v1.8.6 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.12.0 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/jinzhu/inflection v1.0.0 // indirect | ||
github.com/jinzhu/now v1.1.5 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect | ||
github.com/leodido/go-urn v1.2.2 // indirect | ||
github.com/mattn/go-isatty v0.0.18 // indirect | ||
github.com/mattn/go-sqlite3 v1.14.16 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.7 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.11 // indirect | ||
golang.org/x/arch v0.3.0 // indirect | ||
golang.org/x/net v0.8.0 // indirect | ||
golang.org/x/sys v0.6.0 // indirect | ||
golang.org/x/text v0.8.0 // indirect | ||
google.golang.org/protobuf v1.30.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
gorm.io/driver/sqlite v1.5.1 // indirect | ||
) |
File renamed without changes.
File renamed without changes.
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,20 @@ | ||
package auth | ||
|
||
import ( | ||
"fmt" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type User struct { | ||
gorm.Model | ||
FirstName string `json:"first_name" binding:"required"` | ||
LastName string `json:"last_name" binding:"required"` | ||
Email string `json:"email" binding:"required" gorm:"unique;not null"` | ||
Password string `json:"-" binding:"required"` | ||
Active bool `json:"active"` | ||
Admin bool `json:"admin"` | ||
} | ||
|
||
func (user *User) FullName() string { | ||
return fmt.Sprintf("%v %v", user.FirstName, user.LastName) | ||
} |
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 auth | ||
|
||
type AuthState bool | ||
|
||
var activateUserOnCreation AuthState = true | ||
var skipEmailVerification AuthState = false | ||
var defaultAdminStatus AuthState = false | ||
|
||
// modify the setting like this in project settings | ||
// auth.AuthSettings.NewUserState = auth.AuthState(true) | ||
|
||
type AuthAppSettings struct { | ||
NewUserState AuthState | ||
NewUserAdminState AuthState | ||
EmailVerification AuthState | ||
EmailVerificationBackend AuthEmailVerificationBackend | ||
} | ||
|
||
var AuthSettings = AuthAppSettings{ | ||
NewUserState: activateUserOnCreation, | ||
EmailVerification: skipEmailVerification, | ||
NewUserAdminState: defaultAdminStatus, | ||
} |
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,9 @@ | ||
package auth | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
func Urls(r *gin.Engine) { | ||
r.POST("/signup", UserSignUp) | ||
r.POST("/login", UserLogin) | ||
r.GET("/profile", LoginRequiredMiddleware, UserProfile) | ||
} |
Oops, something went wrong.