1.0.12 • Published 4 years ago

forge-auth-module v1.0.12

Weekly downloads
8
License
ISC
Repository
github
Last release
4 years ago

forge.solutions internal module for dealing with auth api

Usage

First of all install this module: npm install forge-auth-module

Then import it: import AuthModule from 'forge-auth-module';

Create instance:

const authModule = new AuthModule({
    endpoint: 'http://localhost:3000',
    auth: {
        AUTH_USERNAME: {{YOUR AUTH_USERNAME}},
        AUTH_PASSWORD: {{YOUR AUTH_PASSWORD}},
    }
})

Then you can check auth credentials with checkCredentials() method:

console.log('credentials: ', await authModule.checkCredentials())

And then you can use all other methods to interact with api

Example bootstrap

import AuthModule from 'forge-auth-module';
const authModule = new AuthModule({
    endpoint: 'http://localhost:3040',
    auth: {
        AUTH_USERNAME: 'TEST_USER',
        AUTH_PASSWORD: 'TEST_USER',
    }
})
async function b() {
    console.log('credentials: ', await authModule.checkCredentials()) // returns `Auth` if credentials correct or `false` if not
    console.log('authenticate: ', await authModule.authenticate({username: '123@botkooper.tk', password: '123ASDasd', app_id: '1'})) // returns User if credentials are correct and `false` if not
}
b()

Objects

type User = {
    id: string;
    username: string;
    meta: object;
    registration_date: number;
    app_id: string;
    status: string;
    verification_code: string | null;
}

type AppPermissions = {
    app: {
        create: boolean,
        read: boolean,
        update: boolean,
        delete: boolean
    }
    entities: {
        [entity: string]: {
            create: boolean,
            read: boolean,
            update: boolean,
            delete: boolean
        }
    }
}

type Auth = {
    AUTH_USERNAME: string,
    AUTH_PASSWORD: string,
    app_auth_id: string,
    permissions: {
        local: {
            [app_id: string]: AppPermissions
        }
        global: {
            create: boolean,
            read: boolean,
            update: boolean,
            delete: boolean
        }
    }
}

Methods

All methods are returning Promise<T | false>, where T means result (pointer safe); and false that means that something wrong happened (invalid credentials / permission issue / something is broken inside of package)

checkToken(params: {token: string})
authenticate(params: {username: string, password: string, app_id: string})
register(params: {username: string, password: string, app_id: string})
verify(params: {verification_code: string, app_id: string})
changePassword(params: {id: string, oldPassword: string, newPassword: string})
preparePasswordRecovery(params: {username: string, app_id: string})
proceedPasswordRecovery(params: {verification_code: string, app_id: string, password: string})
editUserMeta(params: {id: string, meta: any})
1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago