-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a39d01
commit f7289dd
Showing
10 changed files
with
102 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/FrosTiK-SD/authV2/controller" | ||
"github.com/FrosTiK-SD/authV2/model" | ||
mongik "github.com/FrosTiK-SD/mongik/models" | ||
"github.com/lestrrat-go/jwx/v2/jwk" | ||
) | ||
|
||
type Mode string | ||
|
||
const ( | ||
HANDLER Mode = "HANDLER" | ||
MIDDLEWARE Mode = "MIDDLEWARE" | ||
) | ||
|
||
type Session struct { | ||
Student *model.StudentPopulated | ||
} | ||
|
||
type Handler struct { | ||
MongikClient *mongik.Mongik | ||
JwkSet *jwk.Set | ||
Session *Session | ||
Config Config | ||
} | ||
|
||
type Config struct { | ||
Mode Mode | ||
} | ||
|
||
func NewAuthClient(mongik *mongik.Mongik) *Handler { | ||
defaultJwkSet, _ := controller.GetJWKs(mongik.CacheClient, false) | ||
return &Handler{ | ||
MongikClient: mongik, | ||
JwkSet: defaultJwkSet, | ||
Config: Config{ | ||
Mode: MIDDLEWARE, | ||
}, | ||
} | ||
} |
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,27 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// For Gin based middlewares | ||
func (h *Handler) GinVerifyStudent(ctx *gin.Context) { | ||
|
||
// Create a new session | ||
currentHandler := Handler{ | ||
MongikClient: h.MongikClient, | ||
JwkSet: h.JwkSet, | ||
Session: &Session{}, | ||
Config: Config{ | ||
Mode: MIDDLEWARE, | ||
}, | ||
} | ||
|
||
currentHandler.HandlerVerifyStudentIdToken(ctx) | ||
student := currentHandler.Session.Student | ||
|
||
if student != nil { | ||
ctx.Set("student", student) | ||
ctx.Next() | ||
} | ||
} |
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