Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@adonisjs/auth

Package Overview
Dependencies
Maintainers
2
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adonisjs/auth - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

build/src/Exceptions/AuthenticationFailureException.d.ts

6

build/src/Auth/index.d.ts

@@ -1,5 +0,5 @@

import { AuthContract, AuthenticatorsList, AuthManagerContract } from '@ioc:Adonis/Addons/Auth';
import { AuthContract, GuardsList, AuthManagerContract } from '@ioc:Adonis/Addons/Auth';
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
/**
* Auth class exposes the API to obtain authenticator instances for a given
* Auth class exposes the API to obtain guard instances for a given
* HTTP request.

@@ -18,3 +18,3 @@ */

*/
use(mapping: keyof AuthenticatorsList): any;
use(mapping: keyof GuardsList): any;
}

@@ -12,3 +12,3 @@ "use strict";

/**
* Auth class exposes the API to obtain authenticator instances for a given
* Auth class exposes the API to obtain guard instances for a given
* HTTP request.

@@ -15,0 +15,0 @@ */

import { IocContract } from '@adonisjs/fold';
import { AuthConfig, AuthenticatorsList, AuthManagerContract, ExtendProviderCallback, ExtendAuthenticatorCallback } from '@ioc:Adonis/Addons/Auth';
import { AuthConfig, GuardsList, AuthManagerContract, ExtendGuardCallback, ExtendProviderCallback } from '@ioc:Adonis/Addons/Auth';
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
import { Authenticatable as LucidAuthenticatable } from '../Providers/Lucid/Authenticatable';
import { Authenticatable as DatabaseAuthenticatable } from '../Providers/Database/Authenticatable';
/**
* Auth manager to instantiate authentication driver objects
* Auth manager to manage guards and providers object. The extend API can
* be used to add custom guards and providers
*/
export declare class AuthManager implements AuthManagerContract {
private container;
private config;
private container;
static LucidAuthenticatable: typeof LucidAuthenticatable;
static DatabaseAuthenticatable: typeof DatabaseAuthenticatable;
/**

@@ -19,16 +16,24 @@ * Extended set of providers

/**
* Extend set of authenticators
* Extend set of guards
*/
private extendAuthenticators;
constructor(config: AuthConfig, container: IocContract);
private extendedGuards;
constructor(container: IocContract, config: AuthConfig);
/**
* Makes an instance of lucid provider
* Verifies and returns the app secret key
*/
private getAppKey;
/**
* Verifies and returns an instance of the event emitter
*/
private getEmitter;
/**
* Lazily makes an instance of the lucid provider
*/
private makeLucidProvider;
/**
* Makes an instance of database provider
* Lazily makes an instance of the database provider
*/
private makeDatabaseProvider;
/**
* Returns an instance of an extended provider
* Returns an instance of the extended provider
*/

@@ -41,18 +46,18 @@ private makeExtendedProvider;

/**
* Returns an instance of the session driver
* Returns an instance of the session guard
*/
private makeSessionDriver;
private makeSessionGuard;
/**
* Returns an instance of the extended authenticator
* Returns an instance of the extended guard
*/
private makeExtendedAuthenticator;
private makeExtendedGuard;
/**
* Makes authenticator instance for the defined driver inside the
* Makes guard instance for the defined driver inside the
* mapping config.
*/
private makeAuthenticatorInstance;
private makeGuardInstance;
/**
* Make an instance of a given mapping for the current HTTP request.
*/
makeMapping(ctx: HttpContextContract, mapping: keyof AuthenticatorsList): any;
makeMapping(ctx: HttpContextContract, mapping: keyof GuardsList): any;
/**

@@ -63,6 +68,6 @@ * Returns an instance of the auth class for the current request

/**
* Extend auth by adding custom providers and authenticators
* Extend auth by adding custom providers and guards
*/
extend(type: 'provider', name: string, callback: ExtendProviderCallback): void;
extend(type: 'authenticator', name: string, callback: ExtendAuthenticatorCallback): void;
extend(type: 'guard', name: string, callback: ExtendGuardCallback): void;
}

@@ -13,11 +13,10 @@ "use strict";

const Auth_1 = require("../Auth");
const Authenticatable_1 = require("../Providers/Lucid/Authenticatable");
const Authenticatable_2 = require("../Providers/Database/Authenticatable");
/**
* Auth manager to instantiate authentication driver objects
* Auth manager to manage guards and providers object. The extend API can
* be used to add custom guards and providers
*/
class AuthManager {
constructor(config, container) {
constructor(container, config) {
this.container = container;
this.config = config;
this.container = container;
/**

@@ -28,9 +27,29 @@ * Extended set of providers

/**
* Extend set of authenticators
* Extend set of guards
*/
this.extendAuthenticators = new Map();
this.extendedGuards = new Map();
}
/**
* Makes an instance of lucid provider
* Verifies and returns the app secret key
*/
getAppKey() {
const appKey = this.container.use('Adonis/Core/Config').get('app.appKey');
if (!appKey) {
throw new utils_1.Exception('"app.appKey" is required by the auth provider', 500, 'E_MISSING_APP_KEY');
}
return appKey;
}
/**
* Verifies and returns an instance of the event emitter
*/
getEmitter() {
const hasEmitter = this.container.hasBinding('Adonis/Core/Event');
if (!hasEmitter) {
throw new utils_1.Exception('"Adonis/Core/Event" is required by the auth provider');
}
return this.container.use('Adonis/Core/Event');
}
/**
* Lazily makes an instance of the lucid provider
*/
makeLucidProvider(config) {

@@ -40,3 +59,3 @@ return new (require('../Providers/Lucid').LucidProvider)(this.container, config);

/**
* Makes an instance of database provider
* Lazily makes an instance of the database provider
*/

@@ -48,3 +67,3 @@ makeDatabaseProvider(config) {

/**
* Returns an instance of an extended provider
* Returns an instance of the extended provider
*/

@@ -65,38 +84,42 @@ makeExtendedProvider(config) {

}
if (providerConfig.driver === 'lucid') {
return this.makeLucidProvider(providerConfig);
switch (providerConfig.driver) {
case 'lucid':
return this.makeLucidProvider(providerConfig);
case 'database':
return this.makeDatabaseProvider(providerConfig);
default:
return this.makeExtendedProvider(providerConfig);
}
if (providerConfig.driver === 'database') {
return this.makeDatabaseProvider(providerConfig);
}
return this.makeExtendedProvider(providerConfig);
}
/**
* Returns an instance of the session driver
* Returns an instance of the session guard
*/
makeSessionDriver(mapping, config, provider, ctx) {
return new (require('../Drivers/Session').SessionDriver)(this.container, mapping, config, provider, ctx);
makeSessionGuard(mapping, config, provider, ctx) {
const { SessionGuard } = require('../Guards/Session');
return new SessionGuard(mapping, config, this.getAppKey(), this.getEmitter(), provider, ctx);
}
/**
* Returns an instance of the extended authenticator
* Returns an instance of the extended guard
*/
makeExtendedAuthenticator(mapping, config, provider, ctx) {
const authenticatorCallback = this.extendAuthenticators.get(config.driver);
if (!authenticatorCallback) {
throw new utils_1.Exception(`Invalid authenticator driver "${config.driver}" property`);
makeExtendedGuard(mapping, config, provider, ctx) {
const guardCallback = this.extendedGuards.get(config.driver);
if (!guardCallback) {
throw new utils_1.Exception(`Invalid guard driver "${config.driver}" property`);
}
return authenticatorCallback(this.container, mapping, config, ctx, provider);
return guardCallback(this.container, mapping, config, provider, ctx);
}
/**
* Makes authenticator instance for the defined driver inside the
* Makes guard instance for the defined driver inside the
* mapping config.
*/
makeAuthenticatorInstance(mapping, mappingConfig, provider, ctx) {
makeGuardInstance(mapping, mappingConfig, provider, ctx) {
if (!mappingConfig || !mappingConfig.driver) {
throw new utils_1.Exception('Invalid auth config, missing "driver" property');
}
if (mappingConfig.driver === 'session') {
return this.makeSessionDriver(mapping, mappingConfig, provider, ctx);
switch (mappingConfig.driver) {
case 'session':
return this.makeSessionGuard(mapping, mappingConfig, provider, ctx);
default:
return this.makeExtendedGuard(mapping, mappingConfig, provider, ctx);
}
return this.makeExtendedAuthenticator(mapping, mappingConfig, provider, ctx);
}

@@ -109,3 +132,3 @@ /**

const provider = this.makeProviderInstance(mappingConfig.provider);
return this.makeAuthenticatorInstance(mapping, mappingConfig, provider, ctx);
return this.makeGuardInstance(mapping, mappingConfig, provider, ctx);
}

@@ -122,4 +145,4 @@ /**

}
if (type === 'authenticator') {
this.extendAuthenticators.set(name, callback);
if (type === 'guard') {
this.extendedGuards.set(name, callback);
}

@@ -129,3 +152,1 @@ }

exports.AuthManager = AuthManager;
AuthManager.LucidAuthenticatable = Authenticatable_1.Authenticatable;
AuthManager.DatabaseAuthenticatable = Authenticatable_2.Authenticatable;
import { IocContract } from '@adonisjs/fold';
import { DatabaseContract } from '@ioc:Adonis/Lucid/Database';
import { QueryClientContract } from '@ioc:Adonis/Lucid/Database';
import { DatabaseProviderUser, DatabaseProviderConfig, AuthenticatableContract, DatabaseProviderContract } from '@ioc:Adonis/Addons/Auth';
import { DatabaseContract, QueryClientContract } from '@ioc:Adonis/Lucid/Database';
import { DatabaseProviderRow, ProviderUserContract, DatabaseProviderConfig, DatabaseProviderContract } from '@ioc:Adonis/Addons/Auth';
/**
* Database provider to lookup users
* Database provider to lookup users inside the database
*/
export declare class DatabaseProvider implements DatabaseProviderContract<DatabaseProviderUser> {
export declare class DatabaseProvider implements DatabaseProviderContract<DatabaseProviderRow> {
private container;

@@ -20,2 +19,6 @@ private config;

private connection?;
/**
* Name of the member me token column
*/
private rememberMeColumn;
constructor(container: IocContract, config: DatabaseProviderConfig, db: DatabaseContract);

@@ -35,2 +38,11 @@ /**

/**
* Executes the query to find the user, calls the registered hooks
* and wraps the result inside [[ProviderUserContract]]
*/
private findUser;
/**
* Returns an instance of provider user
*/
getUserFor(user: any): ProviderUserContract<DatabaseProviderRow>;
/**
* Define custom connection

@@ -50,7 +62,7 @@ */

*/
findById(id: string | number): Promise<any>;
findById(id: string | number): Promise<ProviderUserContract<DatabaseProviderRow>>;
/**
* Returns a user row using a specific token type and value
*/
findByToken(id: number | string, token: string): Promise<any>;
findByToken(id: number | string, token: string): Promise<ProviderUserContract<DatabaseProviderRow>>;
/**

@@ -60,7 +72,7 @@ * Returns the user row by searching the uidValue against

*/
findByUid(uidValue: string): Promise<any>;
findByUid(uidValue: string): Promise<ProviderUserContract<DatabaseProviderRow>>;
/**
* Updates the user remember me token
*/
updateRememberMeToken(user: AuthenticatableContract<DatabaseProviderUser>): Promise<void>;
updateRememberMeToken(user: ProviderUserContract<DatabaseProviderRow>): Promise<void>;
}

@@ -13,4 +13,5 @@ "use strict";

const utils_1 = require("@poppinss/utils");
const User_1 = require("./User");
/**
* Database provider to lookup users
* Database provider to lookup users inside the database
*/

@@ -26,2 +27,6 @@ class DatabaseProvider {

this.hooks = new hooks_1.Hooks();
/**
* Name of the member me token column
*/
this.rememberMeColumn = 'remember_me_token';
}

@@ -47,2 +52,8 @@ /**

ensureUserHasId(user) {
/**
* Ignore when user is null
*/
if (!user) {
return;
}
if (!user[this.config.identifierKey]) {

@@ -53,2 +64,21 @@ throw new utils_1.Exception(`Auth database provider expects "${this.config.usersTable}.${this.config.identifierKey}" to always exist`);

/**
* Executes the query to find the user, calls the registered hooks
* and wraps the result inside [[ProviderUserContract]]
*/
async findUser(query) {
await this.hooks.exec('before', 'findUser', query);
const user = await query.first();
if (user) {
await this.hooks.exec('after', 'findUser', user);
}
return this.getUserFor(user);
}
/**
* Returns an instance of provider user
*/
getUserFor(user) {
this.ensureUserHasId(user);
return this.container.make((this.config.user || User_1.DatabaseUser), [user, this.config]);
}
/**
* Define custom connection

@@ -79,9 +109,3 @@ */

const query = this.getUserQueryBuilder();
await this.hooks.exec('before', 'findUser', query);
const user = await query.where(this.config.identifierKey, id).first();
if (user) {
this.ensureUserHasId(user);
await this.hooks.exec('after', 'findUser', user);
}
return this.container.make(this.config.authenticatable, [user, this.config]);
return this.findUser(query.where(this.config.identifierKey, id));
}

@@ -92,13 +116,7 @@ /**

async findByToken(id, token) {
const query = this.getUserQueryBuilder();
await this.hooks.exec('before', 'findUser', query);
const user = await query
.where(this.config.identifierKey, id)
.where('remember_me_token', token)
.first();
if (user) {
this.ensureUserHasId(user);
await this.hooks.exec('after', 'findUser', user);
}
return this.container.make(this.config.authenticatable, [user, this.config]);
const query = this
.getUserQueryBuilder()
.where(this.rememberMeColumn, token)
.where(this.config.identifierKey, id);
return this.findUser(query);
}

@@ -111,10 +129,4 @@ /**

const query = this.getUserQueryBuilder();
await this.hooks.exec('before', 'findUser', query);
this.config.uids.forEach((uid) => query.orWhere(uid, uidValue));
const user = await query.first();
if (user) {
this.ensureUserHasId(user);
await this.hooks.exec('after', 'findUser', user);
}
return this.container.make(this.config.authenticatable, [user, this.config]);
return this.findUser(query);
}

@@ -125,2 +137,3 @@ /**

async updateRememberMeToken(user) {
this.ensureUserHasId(user);
await this

@@ -127,0 +140,0 @@ .getUserQueryBuilder()

import { IocContract } from '@adonisjs/fold';
import { QueryClientContract } from '@ioc:Adonis/Lucid/Database';
import { LucidProviderUser, LucidProviderConfig, LucidProviderContract, AuthenticatableContract } from '@ioc:Adonis/Addons/Auth';
import { LucidProviderModel, LucidProviderConfig, ProviderUserContract, LucidProviderContract } from '@ioc:Adonis/Addons/Auth';
/**
* Lucid provider uses Lucid models to lookup a users
*/
export declare class LucidProvider implements LucidProviderContract<LucidProviderUser> {
export declare class LucidProvider implements LucidProviderContract<LucidProviderModel> {
private container;
private config;
/**
* Hooks reference
*/
private hooks;
/**
* Custom connection or query client
*/
private connection?;
constructor(container: IocContract, config: LucidProviderConfig<LucidProviderUser>);
constructor(container: IocContract, config: LucidProviderConfig<LucidProviderModel>);
/**

@@ -22,2 +28,12 @@ * The models options for constructing a query

/**
* Executes the query to find the user, calls the registered hooks
* and wraps the result inside [[ProviderUserContract]]
*/
private findUser;
/**
* Returns an instance of the [[ProviderUser]] by wrapping lucid model
* inside it
*/
getUserFor(user: InstanceType<LucidProviderModel> | null): any;
/**
* Define custom connection

@@ -50,3 +66,3 @@ */

*/
updateRememberMeToken(authenticatable: AuthenticatableContract<InstanceType<LucidProviderUser>>): Promise<void>;
updateRememberMeToken(authenticatable: ProviderUserContract<InstanceType<LucidProviderModel>>): Promise<void>;
}

@@ -12,2 +12,3 @@ "use strict";

const hooks_1 = require("@poppinss/hooks");
const User_1 = require("./User");
/**

@@ -20,2 +21,5 @@ * Lucid provider uses Lucid models to lookup a users

this.config = config;
/**
* Hooks reference
*/
this.hooks = new hooks_1.Hooks();

@@ -27,6 +31,9 @@ }

getModelOptions() {
if (!this.connection) {
return this.config.connection ? { connection: this.config.connection } : {};
if (typeof (this.connection) === 'string') {
return { connection: this.connection };
}
return typeof (this.connection) === 'string' ? { connection: this.connection } : { client: this.connection };
if (this.connection) {
return { client: this.connection };
}
return this.config.connection ? { connection: this.config.connection } : {};
}

@@ -40,2 +47,21 @@ /**

/**
* Executes the query to find the user, calls the registered hooks
* and wraps the result inside [[ProviderUserContract]]
*/
async findUser(query) {
await this.hooks.exec('before', 'findUser', query);
const user = await query.first();
if (user) {
await this.hooks.exec('after', 'findUser', user);
}
return this.getUserFor(user);
}
/**
* Returns an instance of the [[ProviderUser]] by wrapping lucid model
* inside it
*/
getUserFor(user) {
return this.container.make((this.config.user || User_1.LucidUser), [user, this.config]);
}
/**
* Define custom connection

@@ -65,15 +91,4 @@ */

async findById(id) {
/**
* Pull query builder instance and execute the before hook
*/
const query = this.getModelQuery();
await this.hooks.exec('before', 'findUser', query);
const user = await query.where(this.config.identifierKey, id).first();
/**
* Execute hook when user has been found
*/
if (user) {
await this.hooks.exec('after', 'findUser', user);
}
return this.container.make(this.config.authenticatable, [user, this.config]);
return this.findUser(query.where(this.config.identifierKey, id));
}

@@ -84,18 +99,4 @@ /**

async findByToken(id, value) {
/**
* Pull query builder instance and execute the before hook
*/
const query = this.getModelQuery();
await this.hooks.exec('before', 'findUser', query);
const user = await query
.where(this.config.identifierKey, id)
.where('rememberMeToken', value)
.first();
/**
* Execute hook when user has been found
*/
if (user) {
await this.hooks.exec('after', 'findUser', user);
}
return this.container.make(this.config.authenticatable, [user, this.config]);
return this.findUser(query.where(this.config.identifierKey, id).where('rememberMeToken', value));
}

@@ -107,16 +108,5 @@ /**

async findByUid(uidValue) {
/**
* Pull query builder instance and execute the before hook
*/
const query = this.getModelQuery();
await this.hooks.exec('before', 'findUser', query);
this.config.uids.forEach((uid) => (query.orWhere(uid, uidValue)));
const user = await query.first();
/**
* Execute hook when user has been found
*/
if (user) {
await this.hooks.exec('after', 'findUser', user);
}
return this.container.make(this.config.authenticatable, [user, this.config]);
return this.findUser(query);
}

@@ -123,0 +113,0 @@ /**

# The MIT License
Copyright 2019 Harminder virk, contributors
Copyright 2020 Harminder virk, contributors

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

{
"name": "@adonisjs/auth",
"version": "4.0.0",
"version": "4.0.1",
"description": "Offical authentication provider for Adonis framework",
"main": "build/providers/AuthProvider.js",
"files": [
"build/adonis-typings",
"build/providers",
"build/src",
"build/templates"
],
"types": "build/adonis-typings/index.d.ts",

@@ -17,10 +10,11 @@ "scripts": {

"test": "node japaFile.js",
"lint": "tslint --project tsconfig.json",
"clean": "del build",
"copyfiles": "copyfiles \"templates/**/*.txt\" build",
"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile && npm run copyfiles",
"build": "npm run compile",
"commit": "git-cz",
"release": "np",
"version": "npm run build"
"version": "npm run build",
"lint": "eslint . --ext=.ts",
"prepublishOnly": "npm run build"
},

@@ -60,2 +54,4 @@ "keywords": [

"doctoc": "^1.4.0",
"eslint": "^6.8.0",
"eslint-plugin-adonis": "^1.0.8",
"husky": "^4.2.3",

@@ -71,4 +67,2 @@ "japa": "^3.0.1",

"ts-node": "^8.7.0",
"tslint": "^6.1.0",
"tslint-eslint-rules": "^5.4.0",
"typescript": "^3.8.3"

@@ -128,3 +122,9 @@ },

]
}
},
"main": "build/index.js",
"files": [
"build/src",
"build/index.d.ts",
"build/index.js"
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc