auth clean up and redirect fixes
This commit is contained in:
@@ -20,10 +20,9 @@ import (
|
||||
|
||||
type (
|
||||
Auth struct {
|
||||
log *logging.Logger
|
||||
auth *authentication.Authenticator
|
||||
newLoginURL LoginURLProviderFunc
|
||||
accts *accounts.Store
|
||||
log *logging.Logger
|
||||
auth *authentication.Authenticator
|
||||
accts *accounts.Store
|
||||
}
|
||||
|
||||
Identity struct {
|
||||
@@ -41,26 +40,24 @@ type (
|
||||
func NewAuth(
|
||||
logger *logging.Logger,
|
||||
auth *authentication.Authenticator,
|
||||
newLoginURL LoginURLProviderFunc,
|
||||
accts *accounts.Store,
|
||||
) *Auth {
|
||||
return &Auth{
|
||||
log: logger,
|
||||
auth: auth,
|
||||
newLoginURL: newLoginURL,
|
||||
accts: accts,
|
||||
log: logger,
|
||||
auth: auth,
|
||||
accts: accts,
|
||||
}
|
||||
}
|
||||
|
||||
// AddIdentityToRequest will add an Identity to the context that can then be retrieved via GetIdentity.
|
||||
func (a *Auth) AddIdentityToRequest(c *gin.Context) {
|
||||
if err := a.addIdentityToRequest(c); err != nil {
|
||||
// AddIdentity will add an Identity to the context that can then be retrieved via GetIdentity.
|
||||
func (a *Auth) AddIdentity(c *gin.Context) {
|
||||
if err := a.addIdentity(c); err != nil {
|
||||
c.Error(err)
|
||||
c.Abort()
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Auth) addIdentityToRequest(c *gin.Context) error {
|
||||
func (a *Auth) addIdentity(c *gin.Context) error {
|
||||
r := c.Request
|
||||
|
||||
ck, err := r.Cookie("access_token")
|
||||
@@ -101,7 +98,7 @@ func (a *Auth) addIdentityToRequest(c *gin.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Authenticate should only be used along with and after AddIdentityToRequest
|
||||
// Authenticate should only be used along with and after AddIdentity
|
||||
// Typically used with response.Handler to make a gin.HandlerFunc.
|
||||
func (a *Auth) Authenticate(assertions ...AuthorizationAssertions) func(c *gin.Context) (response.Response, error) {
|
||||
return func(c *gin.Context) (response.Response, error) {
|
||||
|
||||
Reference in New Issue
Block a user