Type Identity - a powerful and highly customizable authentication and authrozation and access-control framework

Overview

Description

Type Identity is a powerful and highly customizable authentication and authrozation and access-control framework. It is the de-facto standard for securing Type Script api beta release

Deployment

To deploy this project run

 
  npm run   type-identity

Demo

1- initialize database configuration (this step is required)

export class dbConfig extends IDbConstraint {
    type: String = "mssql";
    host: String = "localhost";
    username: any = "mms";
    password: any = "mms";
    database: any = "TypeIdentity";
    constructor() {
        super();
        this.setUserEntity(CustomUser) //this is option if you want to add new columns in user entity : note this CustomUser will be create on  step number 10 below
    }
}

2- initialize type identity framework database configuration (this step is required)

//this step is not required but if you want to change cookies configuration such as name etc...
export class customCookiesConfig extends CookiesConfiguration{

    name="saeed2022"; //cookies name
    loginPage="/login"; //unauthorize  redirect page
    successfullyPage="https://www.linkedin.com/in/saeed-mohammed-al-obidi-289082147/" //success Page
}

export async function initTypeIdentity() {

    new TypeIdentity()
        .seCookiesConfig(customCookiesConfig) // note this section  is dependency if you want custmize your cookies data
        .setDatabaseConfig(dbConfig).build()
}

3- migration type identity table in database (first when you want add type identity table)

//call this function 
  export async function Migration() {
    await new TypeIdentity().migrationConfig()

}

4- create new Roles

().build() const vaue1 = await _role_manager.addAsync(_Admin) const vaue2 = await _role_manager.addAsync(_Guest) console.log(vaue1, vaue2) } ">
  export async function createRoles() {

    const _Admin = new IdentityRoles()
    _Admin.name = "admin"

    const _Guest = new IdentityRoles()
    _Guest.name = "guest"

    const _role_manager = new RoleManager<IdentityRoles, IdentityRoleClaims>().build()
    const vaue1 = await _role_manager.addAsync(_Admin)
    const vaue2 = await _role_manager.addAsync(_Guest)

    console.log(vaue1, vaue2)
}

5- create new Permisstion

export async function createPermisstion() {
    const _role_manager = new RoleManager<IdentityRoles, IdentityRoleClaims>().build()


    const _Admin = await _role_manager.getRolesByNameAsync("admin")
    const _Guest = await _role_manager.getRolesByNameAsync("guest")

    //admin Permisstion
    const read_Permisstion_admin = new IdentityRoleClaims()
    read_Permisstion_admin.roleId = _Admin.id;
    read_Permisstion_admin.claimType = "permisstion"
    read_Permisstion_admin.claimValue = "Read"

    const writePermisstion_admin = new IdentityRoleClaims()
    writePermisstion_admin.roleId = _Admin.id;
    writePermisstion_admin.claimType = "permisstion"
    writePermisstion_admin.claimValue = "Write"



    //admin Permisstion
    const read_ermisstion_guest = new IdentityRoleClaims()
    read_ermisstion_guest.roleId = _Admin.id;
    read_ermisstion_guest.claimType = "permisstion"
    read_ermisstion_guest.claimValue = "Read"





    const vaue1 = await _role_manager.addPermisstionAsync(read_Permisstion_admin)
    const vaue2 = await _role_manager.addPermisstionAsync(writePermisstion_admin)
    const vaue3 = await _role_manager.addPermisstionAsync(read_ermisstion_guest)
    console.log(vaue1, vaue2, vaue3)
}

6-create new user

().build() const vaue = await _user_manager.addAsync(_user) console.log(vaue) } ">
export async function createUser() {

    const _user = new CustomUser()
    _user.name = "saeed mohammed alabidi"
    _user.userName = "[email protected]"
    _user.passwordHash = "Baru"

    const _user_manager = await new UserManager<CustomUser, IdentityUserClaims>().build()
    const vaue = await _user_manager.addAsync(_user)
    console.log(vaue)
}

7-assign Role To User

export async function assignRoleToUser() {
    const _role_manager = new RoleManager<IdentityRoles, IdentityRoleClaims>().build()
    const _user_manager = new UserManager<CustomUser, IdentityUserClaims>().build()

    const admin = await _role_manager.getRolesByNameAsync("guest")
    const user = await _user_manager.FindByUserNameAsync("[email protected]")
    user.RoleId = admin.id
    user.RoleName = admin.name
    const vaue = await _user_manager.updateAsync(user)
    console.log(vaue)
}

8-signIn: this can call when user login

export async function signIn(req, res) {
    const _role_manager = new RoleManager<IdentityRoles, IdentityRoleClaims>().build()
    const _user_manager = new UserManager<CustomUser, IdentityUserClaims>().build()
    const _sign_manager = new SignManager<CustomUser, IdentityRoleClaims>().build(req, res)
    const user = await _user_manager.FindByUserNameAsync("[email protected]")
    _sign_manager.SignInAsync(user, true)
}


9-signOut: this can call when user logout

export async function signOut(req, res) {

    var _sign_manager = new SignManager<CustomUser, IdentityRoleClaims>().build(req, res)
    await _sign_manager.SignOutAsync()
}

9- create custom user entity or any type identity entity

{ @Column("int", { name: "countryId", nullable: true }) countryId: Number | null = 1 } ">
 
 /** note you must Donwload typeorm from npn 
  *  npm i typeorm
  */
@Entity("CustomUser")
export default class CustomUser extends Users<IdentityUserClaims,IdentityUserLogins,IdentityUserTokens,IdentityRoles>{
    
    @Column("int", { name: "countryId", nullable: true })
    countryId: Number | null = 1
 
}

call type on api

1- create Controller

 /** 
  *  this class have services that consume the request 
  */



import { AuthorizeType } from "type-identity/Idenitiy/Services/AuthorizeServices";
import { Authorize } from "type-identity/Core/Annotation/Authorize";
export default class UserInfo{

    @Authorize(AuthorizeType.Roles,"admin")
    admin(req, res){
      res.send('is Authorize to go as admin')
  
    }


    
    @Authorize(AuthorizeType.Policy,"write")
    write(req, res){
      res.send('is Authorize to write')
  
    }

    @Authorize(AuthorizeType.Roles,"guest")
    quest(req, res){
      res.send('is Authorize to go as  guest')
    }
  }

  

1- create endpoint used express.js

{ console.log('start') await signIn(req, res) }) app.get('/signOut', async (req, res) => { signOut(req, res) }) /** * this endpoint allow for admin if you try to go as guest you will get 401 */ app.get('/adminPermisstin', async (req, res) => { new UserInfo().admin(req, res) }) /** * this endpoint allow for quest */ app.get('/guest', async (req, res) => { new UserInfo().quest(req, res) }) /** * any one have write Policy */ app.get('/guest', async (req, res) => { new UserInfo().write(req, res) }) const port = 3334 app.listen(port, () => { console.log(`Example app listening on port ${port}`) }) ">
 
 /** create file call api.ts
  *   
  */
import UserInfo from "../Controller.ts/UserInfo";
import { initTypeIdentity, signIn, signOut } from "../Services/main";


const cors = require('cors');//this required
var cookieParser = require('cookie-parser')//this required
const express = require('express')//this required
const app = express()  //this required
app.use(cookieParser()) //this required
app.use(cors()) //this required



initTypeIdentity()




app.get('/signIn', async (req, res) => {
    console.log('start')
    await signIn(req, res)
})

app.get('/signOut', async (req, res) => {
    signOut(req, res)
})


/**
 * this endpoint allow for admin if you try to go as guest you will get 401 
 */

app.get('/adminPermisstin', async (req, res) => {
    new UserInfo().admin(req, res)
})




/**
 * this endpoint allow for quest 
 */

app.get('/guest', async (req, res) => {
    new UserInfo().quest(req, res)
})


/**
 * any one have write Policy
 */

app.get('/guest', async (req, res) => {
    new UserInfo().write(req, res)
})


const port = 3334
app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
  })

🔗 Links

linkedin twitter

Authors

🚀 About Me

Saeed Mohammed Al-abidi [email protected] l woud description my self as some one who interesting on building software and frameworks, starting from Design & Architecture, up to implementation and test

You might also like...

A beautiful, responsive, highly customizable and accessible replacement for JavaScript's popup boxes. Zero dependencies.Alerts ,dialogs

AsgarAlert (v1) for JS Install script defer src="/asgar-alert.js"/script Examples The most basic message: asgar("Hello world!"); A message signali

Dec 20, 2022

A highly customizable platform ready to be a portfolio website, and become a lot more with some of your own components

A highly customizable platform ready to be a portfolio website, and become a lot more with some of your own components

Vextra Elegant and animated portfolio website. Demo: vextra.vercel.app Vextra is a portfolio template, packed with animations with a satisfying flow t

Sep 19, 2022

Easy to setup and highly customizable leaderboard with built-in score validation system.

EasyLeaderboard Add a leaderboard to your game in under 10 minutes! 🏃 Ready to go game clients make adding a leaderboard quick and easy đŸ•ĩī¸ Extendabl

Sep 30, 2022

🔨 A more engineered, highly customizable, standard output format commitizen adapter.

🔨 A more engineered, highly customizable, standard output format commitizen adapter.

cz-git Github | Installation | Website | įŽ€äŊ“中文文æĄŖ Introduction A more engineered, highly customizable, standard output format commitizen adapter. What i

Dec 31, 2022

A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control

A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control

Web Control for ZJU Fast-Drone-250 A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control (tested on Xiaomi

Nov 11, 2022

Web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control.

Web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control.

Linux Remote This is a web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control. Do

Jul 6, 2022

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.

JsRender: best-of-breed templating Simple and intuitive, powerful and extensible, lightning fast For templated content in the browser or on Node.js (w

Jan 2, 2023

Sign In With Tezos: Access Control Management using Tezos NFTs

SIWT Sign In With Tezos (SIWT) is a library that supports the development of your decentralized application (dApp) by proving the users ownership of t

Dec 31, 2022

An authorization library that supports access control models like ACL, RBAC, ABAC in modern JavaScript platforms

An authorization library that supports access control models like ACL, RBAC, ABAC in modern JavaScript platforms

Casbin-Core 💖 Looking for an open-source identity and access management solution like Okta, Auth0, Keycloak ? Learn more about: Casdoor News: still w

Oct 20, 2022
Owner
Saeed Mohammed Al-abidi
someone who is interesting in building software and frameworks, starting from Design & Architecture, up to implementation and test
Saeed Mohammed Al-abidi
Open-source NFID SDK for Internet Identity, a blockchain authentication system for the Internet Computer.

NFID-SDK is an open source software development kit that contains examples and packages for developers to integrate NFID into your application

Internet Identity Labs 15 Dec 23, 2022
`raaghu-mfe` is an opensource micro front end framework built on top of `raaghu-elements`, Bootstrap 5 and Storybook offering highly customizable UI components and built-in pages

`raaghu-mfe` is an opensource micro front end framework built on top of `raaghu-elements`, Bootstrap 5 and Storybook offering highly customizable UI components and built-in pages. Raaghu mfe can be used as a base to build complex components and UI layouts whilst maintaining a high level of reusability,flexibility with ease of maintenance.

Wai Technologies 160 Dec 30, 2022
A powerful, extensible, customizable & rapidly develop hacking framework.

YourN3xt(Beta) A powerful, extensible, customizable & rapidly develop hacking framework. Installations Github: https://github.com/OTAKKATO/YourN3xt N

OTAK 4 Nov 21, 2022
Highly customizable checkboxes and radio buttons (jQuery & Zepto)

iCheck plugin 1.0.3 Highly customizable checkboxes and radio buttons for jQuery and Zepto. Refer to the iCheck website for examples. Note: iCheck v2.0

Dar Gullin 7.4k Dec 25, 2022
This simple library allows you to create awesome responsive and highly customizable popups importing just one JavaScript file.

Creativa - Popup This is a simple library that allows you to create awesome popups importing just one JavaScript file. Getting started You can import

Eduardo Mollo 5 Mar 29, 2022
🛡ī¸ Dead-simple, yet highly customizable security middleware for Apollo GraphQL servers and Envelop 🛡ī¸

GraphQL Armor ??ī¸ GraphQL Armor is a dead-simple yet highly customizable security middleware for various GraphQL server engines. Contents Contents Sup

Escape – GraphQL Security 267 Jan 9, 2023
Highly customizable checkboxes and radio buttons (jQuery & Zepto)

iCheck plugin 1.0.3 Highly customizable checkboxes and radio buttons for jQuery and Zepto. Refer to the iCheck website for examples. Note: iCheck v2.0

Dar Gullin 7.5k Aug 24, 2022
A highly customizable homepage (or startpage / application dashboard) with Docker and service API integrations.

Features Web Bookmarks Service Bookmarks Docker Integration Status light + CPU, Memory & Network Reporting (click on the status light) Service Integra

Ben Phelps 3.5k Dec 30, 2022
jQuery easy ticker is a news ticker like plugin, which scrolls the list infinitely. It is highly customizable, flexible with lot of features and works in all browsers.

jQuery Easy Ticker plugin jQuery easy ticker is a news ticker like plugin which scrolls a list infinitely. It is highly customizable, flexible with lo

Aakash Chakravarthy 208 Dec 20, 2022