Fixes unauthorized access
Fetches existing accessToken using refreshToken when refreshing webapp or opening new tab if that fails we generate new accessToken along with refreshToken
This commit is contained in:
@@ -217,6 +217,7 @@ func New(ctx context.Context, log *zap.Logger, s store.Storer, opt options.AuthO
|
||||
Templates: tpls,
|
||||
SessionManager: sesManager,
|
||||
OAuth2: oauth2Server,
|
||||
OAuth2Manager: oauth2Manager,
|
||||
AuthService: systemService.DefaultAuth,
|
||||
UserService: systemService.DefaultUser,
|
||||
ClientService: &clientService{s},
|
||||
|
||||
@@ -351,6 +351,7 @@ func (h AuthHandlers) handleTokenRequest(req *request.AuthReq, client *types.Aut
|
||||
r = req.Request
|
||||
w = req.Response
|
||||
ctx = req.Context()
|
||||
ti oauth2def.TokenInfo
|
||||
)
|
||||
|
||||
req.Status = -1
|
||||
@@ -383,9 +384,15 @@ func (h AuthHandlers) handleTokenRequest(req *request.AuthReq, client *types.Aut
|
||||
), " ")
|
||||
}
|
||||
|
||||
ti, err := h.OAuth2.GetAccessToken(ctx, gt, tgr)
|
||||
if err != nil {
|
||||
return h.tokenError(w, err)
|
||||
if gt == oauth2def.Refreshing {
|
||||
ti, err = h.OAuth2Manager.LoadRefreshToken(ctx, tgr.Refresh)
|
||||
}
|
||||
|
||||
if gt != oauth2def.Refreshing || err != nil {
|
||||
ti, err = h.OAuth2.GetAccessToken(ctx, gt, tgr)
|
||||
if err != nil {
|
||||
return h.tokenError(w, err)
|
||||
}
|
||||
}
|
||||
|
||||
return token(w, h.OAuth2.GetTokenData(ti), nil)
|
||||
|
||||
@@ -88,6 +88,10 @@ type (
|
||||
ValidationBearerToken(r *http.Request) (oauth2.TokenInfo, error)
|
||||
}
|
||||
|
||||
oauth2Manager interface {
|
||||
LoadRefreshToken(ctx context.Context, refresh string) (oauth2.TokenInfo, error)
|
||||
}
|
||||
|
||||
localeService interface {
|
||||
NS(ctx context.Context, ns string) func(key string, rr ...string) string
|
||||
T(ctx context.Context, ns, key string, rr ...string) string
|
||||
@@ -100,6 +104,7 @@ type (
|
||||
Locale localeService
|
||||
Templates templateExecutor
|
||||
OAuth2 oauth2Service
|
||||
OAuth2Manager oauth2Manager
|
||||
SessionManager *request.SessionManager
|
||||
AuthService authService
|
||||
UserService userService
|
||||
|
||||
Reference in New Issue
Block a user