All Projects → joaojosefilho → Vuejsoidcclient

joaojosefilho / Vuejsoidcclient

Licence: mit
project vueJs with oidc-client library

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vuejsoidcclient

Blog.identityserver
🥗 打造一个功能强大的通用型Ids4用户认证授权服务中心,配合之前的所有开源项目
Stars: ✭ 315 (+257.95%)
Mutual labels:  identityserver4
Identityserver4.samples
Samples for IdentityServer4
Stars: ✭ 1,002 (+1038.64%)
Mutual labels:  identityserver4
Blazor Wasm Identity Grpc
Blazor WASM, IdentityServer4, Kestrel Web Server, Entity Framework Code First SQLite Database with Multiple Roles, Additional User Claims & gRPC with Roles Authorization.
Stars: ✭ 61 (-30.68%)
Mutual labels:  identityserver4
Restaurant App
Restaurant App 🍔 is a sample open-source e-Commerce 🛒 application for ordering foods, powered by polyglot microservices architecture and cross-platform development including mobile and web
Stars: ✭ 471 (+435.23%)
Mutual labels:  identityserver4
Jpproject.identityserver4.adminui
🔧 ASP.NET Core 3 & Angular 8 Administration Panel for 💞IdentityServer4 and ASP.NET Core Identity
Stars: ✭ 717 (+714.77%)
Mutual labels:  identityserver4
Buildingblocks
Building blocks for Aspnet Core Microservices Development
Stars: ✭ 43 (-51.14%)
Mutual labels:  identityserver4
Angularaspnetcoreoauth
Sample project demonstrating user authentication and identity with Angular, Asp.Net Core and IdentityServer4
Stars: ✭ 268 (+204.55%)
Mutual labels:  identityserver4
Aspnetcorewindowsauth
Local and Windows Authentication, ASP.NET Core MVC, IdentityServer4
Stars: ✭ 87 (-1.14%)
Mutual labels:  identityserver4
Abp.zerocore.identityserver4.configuration
IdentityServer4 ConfigurationStore(ClientStore,ResourceStore,CorsPolicyService) for Abp(https://github.com/aspnetboilerplate/aspnetboilerplate)
Stars: ✭ 25 (-71.59%)
Mutual labels:  identityserver4
Identityserver4 Swagger Integration
How to get Swashbuckle or NSwag Swagger UI's working with IdentityServer 4
Stars: ✭ 60 (-31.82%)
Mutual labels:  identityserver4
Identityserver4.templates
dotnet new templates for IdentityServer4
Stars: ✭ 559 (+535.23%)
Mutual labels:  identityserver4
Aspnet5identityserverangularimplicitflow
OpenID Connect Code / Implicit Flow with Angular and ASP.NET Core 5 IdentityServer4
Stars: ✭ 670 (+661.36%)
Mutual labels:  identityserver4
Aspnetcoreidentityserver4resourceownerpassword
ASP.NET Core IdentityServer4 Resource Owner Flow Refresh token and custom user repository
Stars: ✭ 44 (-50%)
Mutual labels:  identityserver4
Lin Cms Dotnetcore
😃A simple and practical CMS implemented by .NET 5 + FreeSql;前后端分离、Docker部署、OAtuh2授权登录、自动化部署DevOps、自动同步至Gitee、代码生成器、仿掘金专栏
Stars: ✭ 401 (+355.68%)
Mutual labels:  identityserver4
Aspnetcoreid4external
external OpenID Connect Login to IdentityServer4 with AAD
Stars: ✭ 63 (-28.41%)
Mutual labels:  identityserver4
Jpproject.identityserver4.sso
🔒 ASP.NET Core 3.1 Open Source SSO. Built within IdentityServer4 🔑
Stars: ✭ 298 (+238.64%)
Mutual labels:  identityserver4
Identityserver4
OpenID Connect and OAuth 2.0 Framework for ASP.NET Core
Stars: ✭ 8,428 (+9477.27%)
Mutual labels:  identityserver4
Greatwall
Util应用框架配套的权限管理系统
Stars: ✭ 88 (+0%)
Mutual labels:  identityserver4
Aspnetcorespa
Asp.Net 5.0 & Angular 11 SPA Fullstack application with plenty of examples. Live demo:
Stars: ✭ 1,211 (+1276.14%)
Mutual labels:  identityserver4
Identityserver4.openadmin
Open Source Admin UI for IdentityServer4
Stars: ✭ 54 (-38.64%)
Mutual labels:  identityserver4

vuejsoidcclient

Project vueJs with oidc-client library

Create the development environment

Npm:
https://nodejs.org/en/download/

Npm Version Control on Windows:
https://github.com/felixrieseberg/npm-windows-upgrade

Npm Version Control on Linux:
https://github.com/creationix/nvm

Technology Version

Version of npm used in the project: 6.5.0
Version of oidc-client: 1.6.1

Identity Provider

The configuration for the examples are based on running IdentityServer4 on localhost. A ready-to-go reference implementation for testing purposes can be found at IdentityServer4AndApi.

Documentation

Oidc-Client:
https://github.com/IdentityModel/oidc-client-js/wiki

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run prod

Connection with identity provider

Change the parameters of the variable mgr of the script SecurityService.js to the values of your identity provider.

var mgr = new Oidc.UserManager({
  userStore: new Oidc.WebStorageStateStore(),  
  authority: 'https://localhost:44321',
  client_id: 'vuejsclient',
  redirect_uri: window.location.origin + '/static/callback.html',
  response_type: 'id_token token',
  scope: 'openid profile address roles identityserver4api country subscriptionlevel offline_access',
  post_logout_redirect_uri: window.location.origin + '/index.html',
  silent_redirect_uri: window.location.origin + '/static/silent-renew.html',
  accessTokenExpiringNotificationTime: 10,
  automaticSilentRenew: true,
  filterProtocolClaims: true,
  loadUserInfo: true
})

The script SecurityService.js contains triggers and methods from the oidc-client library.

API

The script ApiService.js is responsible for making requests to an API using the libraries oidc-client and axios

The baseUrl constant receives the static part of the API Url.

const baseUrl = 'https://localhost:44390/api/';

The defineHeaderAxios() method appends the access teken to the axios head.

async defineHeaderAxios () {
    await user.getAcessToken().then(
      acessToken => {
        axios.defaults.headers.common['Authorization'] = 'Bearer ' + acessToken
      }, err => {
        console.log(err)
      })  
  }

The getAll() method makes a get request. It receives as a parameter a string that will be concatenated with the baseUrl constant by forming the API Url.

async getAll(api){
    await this.defineHeaderAxios() 
    return axios
      .get(baseUrl + api)
      .then(response => response.data)
      .catch(err => {
        console.log(err);
      })
  }

Route protection

The script index.js is responsible for managing the application routes using the vue router. Each route has a field called meta. Meta receives two parameters: requiresAuth and role.

  • requiresAuth[Bollean]: Responsible for protecting the route
  • role[String]: Users with this role will be allowed to access the route
{
  path: '/payinguser',
  name: 'PayingUser',
  component: PayingUser,
  meta: {
	requiresAuth: true,
	role: ['PayingUser']
  }
},
{
  path: '/freeuser',
  name: 'FreeUser',
  component: FreeUser,
  meta: {
	requiresAuth: true,
	role: ['FreeUser']
  }
}

At each transition of routes in the application, the router.beforeEach() method of the script index.js is called. This method checks whether the user who is logged in is allowed to access the route. It does this by comparing the role of the user and the role of the route.

router.beforeEach((to, from, next) => {
  const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
  if (requiresAuth) {
      mgr.getRole().then(
        sucess => {
          if (to.meta.role == sucess){
            next();
          }else {
            next('/accessdenied');
          }
        },
        err => {
          console.log(err);
        }
      );    
  } else {
    next();
  }
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].