@adonisjs/auth
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -0,1 +1,17 @@ | ||
<a name="2.0.2"></a> | ||
## [2.0.2](https://github.com/adonisjs/adonis-auth/compare/v2.0.1...v2.0.2) (2017-08-08) | ||
### Bug Fixes | ||
* **test:** add dummy provider for Exceptions ([f308199](https://github.com/adonisjs/adonis-auth/commit/f308199)) | ||
### Features | ||
* **exceptions:** add handlers for exceptions ([70ac097](https://github.com/adonisjs/adonis-auth/commit/70ac097)) | ||
* **schemes:** expose base scheme and few config properties ([60b9e18](https://github.com/adonisjs/adonis-auth/commit/60b9e18)) | ||
<a name="2.0.1"></a> | ||
@@ -2,0 +18,0 @@ ## [2.0.1](https://github.com/adonisjs/adonis-auth/compare/v2.0.0...v2.0.1) (2017-08-05) |
{ | ||
"name": "@adonisjs/auth", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Offical authentication provider for Adonis framework", | ||
@@ -53,2 +53,5 @@ "main": "index.js", | ||
"test/**/*.spec.js" | ||
], | ||
"exclude": [ | ||
"src/ExceptionHandler/index.js" | ||
] | ||
@@ -55,0 +58,0 @@ }, |
@@ -81,3 +81,6 @@ 'use strict' | ||
const Config = this.app.use('Adonis/Src/Config') | ||
const Exception = this.app.use('Adonis/Src/Exception') | ||
require('../src/ExceptionHandler')(Exception) | ||
Context.getter('auth', function () { | ||
@@ -84,0 +87,0 @@ return new Auth({ request: this.request, response: this.response, session: this.session }, Config) |
@@ -15,3 +15,5 @@ 'use strict' | ||
/** | ||
* This exception is raised when user is not found | ||
* This exception is raised when user is not found. This usally | ||
* happens when trying to authenticate user using their | ||
* credentials. | ||
* | ||
@@ -27,3 +29,4 @@ * @class UserNotFoundException | ||
/** | ||
* This exception is raised when user password mis-matches | ||
* This exception is raised when user password mis-matches. This usally | ||
* happens when trying to authenticate user using their credentials. | ||
* | ||
@@ -45,8 +48,23 @@ * @class PasswordMisMatchException | ||
class InvalidLoginException extends GE.LogicalException { | ||
static missingSession () { | ||
return new this('No session found for user', 401, 'E_MISSING_SESSION') | ||
/** | ||
* User session is invalid but trying to use secure | ||
* resource | ||
* | ||
* @method invalidSession | ||
* | ||
* @return {Object} | ||
*/ | ||
static invalidSession () { | ||
return new this('Invalid session', 401, 'E_INVALID_SESSION') | ||
} | ||
static missingBasicAuthCredentials (message) { | ||
return new this('Cannot parser or read Basic auth header', 401, 'E_MISSING_AUTH_HEADER') | ||
/** | ||
* The basic auth header/credentials are misssing | ||
* | ||
* @method missingBasicAuthCredentials | ||
* | ||
* @return {Object} | ||
*/ | ||
static missingBasicAuthCredentials () { | ||
return new this('Cannot parse or read Basic auth header', 401, 'E_MISSING_AUTH_HEADER') | ||
} | ||
@@ -56,22 +74,43 @@ } | ||
/** | ||
* This exception is raised when jwt token is invalid | ||
* is expired | ||
* This exception is raised when jwt token is invalid or | ||
* unable to find user for JWT token. | ||
* | ||
* @class JwtTokenException | ||
* @class InvalidJwtToken | ||
*/ | ||
class JwtTokenException extends InvalidLoginException { | ||
static expired () { | ||
return new this('Token has been expired', 401, 'E_JWT_TOKEN_EXPIRED') | ||
class InvalidJwtToken extends InvalidLoginException { | ||
static invoke (message) { | ||
return new this(message || 'The Jwt token is invalid', 401, 'E_INVALID_JWT_TOKEN') | ||
} | ||
} | ||
static invoke (message) { | ||
return new this(message, 401, 'E_INVALID_JWT_TOKEN') | ||
/** | ||
* This exception is raised when jwt refresh token is | ||
* invalid. | ||
* | ||
* @class InvalidRefreshToken | ||
*/ | ||
class InvalidRefreshToken extends InvalidLoginException { | ||
static invoke (refreshToken) { | ||
return new this(`Invalid refresh token ${refreshToken}`, 401, 'E_INVALID_JWT_REFRESH_TOKEN') | ||
} | ||
} | ||
/** | ||
* This exception is raised when jwt token is expired | ||
* | ||
* @class ExpiredJwtToken | ||
*/ | ||
class ExpiredJwtToken extends InvalidLoginException { | ||
static invoke () { | ||
return new this('The jwt token has been expired. Generate a new one to continue', 401, 'E_JWT_TOKEN_EXPIRED') | ||
} | ||
} | ||
module.exports = { | ||
UserNotFoundException, | ||
PasswordMisMatchException, | ||
JwtTokenException, | ||
InvalidJwtToken, | ||
InvalidRefreshToken, | ||
ExpiredJwtToken, | ||
InvalidLoginException | ||
} |
@@ -12,2 +12,9 @@ 'use strict' | ||
/** | ||
* The base scheme is supposed to be extend by other | ||
* schemes. | ||
* | ||
* @class BaseScheme | ||
* @constructor | ||
*/ | ||
class BaseScheme { | ||
@@ -22,2 +29,35 @@ constructor () { | ||
/** | ||
* The uid field name | ||
* | ||
* @method uidField | ||
* | ||
* @return {String} | ||
*/ | ||
get uidField () { | ||
return this._config.uid | ||
} | ||
/** | ||
* The password field name | ||
* | ||
* @method passwordField | ||
* | ||
* @return {String} | ||
*/ | ||
get passwordField () { | ||
return this._config.password | ||
} | ||
/** | ||
* The scheme in use | ||
* | ||
* @method scheme | ||
* | ||
* @return {String} | ||
*/ | ||
get scheme () { | ||
return this._config.scheme | ||
} | ||
/** | ||
* The primary key value for a given | ||
@@ -24,0 +64,0 @@ * user |
@@ -270,5 +270,3 @@ 'use strict' | ||
if (!user) { | ||
throw CE | ||
.UserNotFoundException | ||
.invoke(`Cannot find user with refresh token as ${refreshToken}`) | ||
throw CE.InvalidRefreshToken.invoke(refreshToken) | ||
} | ||
@@ -316,5 +314,5 @@ | ||
if (name === 'TokenExpiredError') { | ||
throw CE.JwtTokenException.expired() | ||
throw CE.ExpiredJwtToken.invoke() | ||
} | ||
throw CE.JwtTokenException.invoke(message) | ||
throw CE.InvalidJwtToken.invoke(message) | ||
} | ||
@@ -328,5 +326,3 @@ | ||
if (!this.user) { | ||
throw CE | ||
.UserNotFoundException | ||
.invoke(`Cannot find user with ${this.primaryKey} as ${this.jwtPayload.uid}`) | ||
throw CE.InvalidJwtToken.invoke() | ||
} | ||
@@ -333,0 +329,0 @@ return true |
@@ -275,13 +275,3 @@ 'use strict' | ||
/** | ||
* If a user is not found and there is no remeberMeToken | ||
* then throw an exception | ||
*/ | ||
if (!this.user && !rememberMeToken && sessionValue) { | ||
throw CE | ||
.UserNotFoundException | ||
.invoke(`Cannot find user with ${this.primaryKey} as ${sessionValue}`) | ||
} | ||
throw CE.InvalidLoginException.missingSession() | ||
throw CE.InvalidLoginException.invalidSession() | ||
} | ||
@@ -288,0 +278,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72290
32
2142