Comparing version 0.2.23 to 0.2.24
@@ -23,2 +23,3 @@ import { Context } from 'egg'; | ||
private unautorizedRedirectUri?; | ||
private unauthorizedRedirectIgnore?; | ||
private loginHandler?; | ||
@@ -25,0 +26,0 @@ private authHandler?; |
@@ -107,7 +107,9 @@ "use strict"; | ||
const token = ctx.cookies.get('Authorization'); | ||
let sub; | ||
if (this.authHandler) { | ||
const sub = await this.subjectProvider.verify(token); | ||
sub = await this.subjectProvider.verify(token); | ||
if (!sub) { | ||
if (this.unautorizedRedirectUri) { | ||
return ctx.redirect(this.unautorizedRedirectUri); | ||
const redirectIgnored = this.unauthorizedRedirectIgnore && ctx.request.path.startsWith(this.unauthorizedRedirectIgnore); | ||
if (this.unautorizedRedirectUri && !redirectIgnored) { | ||
return ctx.redirect(`${this.unautorizedRedirectUri}?callback=${ctx.request.path}`); | ||
} | ||
@@ -118,11 +120,10 @@ ctx.status = 401; | ||
await this.authHandler(ctx, sub); | ||
if (this.permissionHandler) { | ||
await this.permissionHandler(ctx, sub); | ||
} | ||
} | ||
else { | ||
const authenticationInformation = await this.jwtProvider.verify(token); | ||
sub = authenticationInformation.primaryPrincipal.id; | ||
if (!authenticationInformation) { | ||
if (this.unautorizedRedirectUri) { | ||
return ctx.redirect(this.unautorizedRedirectUri); | ||
const redirectIgnored = this.unauthorizedRedirectIgnore && ctx.request.path.startsWith(this.unauthorizedRedirectIgnore); | ||
if (this.unautorizedRedirectUri && !redirectIgnored) { | ||
return ctx.redirect(`${this.unautorizedRedirectUri}?callback=${ctx.request.path}`); | ||
} | ||
@@ -133,6 +134,6 @@ ctx.status = 401; | ||
this.saveAuthenticationInformationToContext(ctx, authenticationInformation); | ||
if (this.permissionHandler) { | ||
await this.permissionHandler(ctx, authenticationInformation.primaryPrincipal.id); | ||
} | ||
} | ||
if (this.permissionHandler) { | ||
await this.permissionHandler(ctx, sub); | ||
} | ||
return next(); | ||
@@ -173,3 +174,3 @@ }; | ||
this.moziBindUri = kauthConfig.moziBindUri; | ||
this.moziPrompt = kauthConfig.moziPrompt || 'auto'; | ||
this.moziPrompt = kauthConfig.moziPrompt || ''; | ||
this.googleTokenUri = kauthConfig.googleTokenUri; | ||
@@ -183,2 +184,3 @@ this.googleBindUri = kauthConfig.googleBindUri; | ||
this.unautorizedRedirectUri = kauthConfig.unautorizedRedirectUri; | ||
this.unauthorizedRedirectIgnore = kauthConfig.unauthorizedRedirectIgnore; | ||
this.loginHandler = kauthConfig.loginHandler; | ||
@@ -185,0 +187,0 @@ this.authHandler = kauthConfig.authHandler; |
@@ -0,1 +1,10 @@ | ||
## [0.2.24](https://gitlab-ag.marmot-cloud.com/marmot/kauth-sdk-egg/compare/v0.2.23...v0.2.24) (2021-02-04) | ||
### Features | ||
* add unauthorizedRedirectIgnore and redirect with callback ([1546234](https://gitlab-ag.marmot-cloud.com/marmot/kauth-sdk-egg/commit/154623455d3ba89f0f6b882d61ab1c59d3132664)) | ||
## [0.2.23](https://gitlab-ag.marmot-cloud.com/marmot/kauth-sdk-egg/compare/v0.2.22...v0.2.23) (2021-01-25) | ||
@@ -2,0 +11,0 @@ |
{ | ||
"name": "egg-kauth", | ||
"version": "0.2.23", | ||
"version": "0.2.24", | ||
"description": "egg kauth plugin", | ||
@@ -5,0 +5,0 @@ "eggPlugin": { |
29597
454