@mo-platform/auth
Mo authentication library
Last updated 2 months ago by iapain .
MIT · Original npm · Tarball · package.json
$ cnpm install @mo-platform/auth 
SYNC missed versions from official npm registry.

JS client for MoAuth

MoAuth provides an OAuth proxy to various providers. For the time being it only supports Fagbokforlaget e-portal or FEIDE. This js library provides necessary abstraction for authentication from various services.

NOTE: Mo-Auth lib replies on modern browsers and does not includes polyfills for fetch and Promise. You may include them yourself and if you use it inside vue then edit vue.config.js and add transpileDependencies:['@mo-platform/auth']. Also vuejs automatically insers es-promise polyfill but you still have to add polyfill for fetch. We recommend using import whatwg-fetch in your main.js.

Install

npm install @mo-platform/auth

Use

import MoAuth from '@mo-platform/auth'
let auth = new MoAuth()
// do something with auth

Install browser method

// Include polyfills if desired
<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?features=fetch%2Ces2017"></script>
<script
src="https://unpkg.com/@mo-platform/auth@0.6.0/dist/moauth.bundle.js"></script>

<script>
let auth = new moauth()

// initate oauth workflow
auth.authorize({redirectUrl: 'http://locahost:8000', scope: 'mo_apps'}); // url redirect (optional)

// listen to access token in url query
auth
.checkToken()
.then(user) {
  console.log(user);
  //do something with user
}
.catch(err) {
  console.error(err);
}

// To check product access
auth
  .checkToken()
  .then((user) => {
    // Do something
    return auth.checkAccess(['product1'])
  })
  .then((resp) => {
    if (resp.products.includes('product1)) {
      // Success
    }
    else {
      // failure
    }
  })
  .catch((err) => {
    // Handle error
  })


// async await

const user = await auth.checkToken()
const resp = await auth.checkAccess(['product1'])

if (resp.products.includes('product1') {
  // success
}
else {
  // failure
}

// clears localstorage for access token
auth.logout();
</script>

Current Tags

  • 1.0.11                                ...           latest (2 months ago)
  • 0.2.0                                ...           lerna-temp (3 years ago)
  • 0.4.0                                ...           next (3 years ago)

48 Versions

  • 1.0.11                                ...           2 months ago
  • 1.0.10                                ...           8 months ago
  • 1.0.9                                ...           9 months ago
  • 1.0.3                                ...           9 months ago
  • 0.8.0                                ...           10 months ago
  • 0.7.8                                ...           10 months ago
  • 0.7.7                                ...           10 months ago
  • 0.7.6                                ...           10 months ago
  • 0.7.5                                ...           10 months ago
  • 0.7.4                                ...           10 months ago
  • 0.7.3                                ...           10 months ago
  • 0.7.2                                ...           a year ago
  • 0.7.1                                ...           a year ago
  • 0.7.0                                ...           a year ago
  • 0.6.14                                ...           a year ago
  • 0.6.13                                ...           a year ago
  • 0.6.12                                ...           a year ago
  • 0.6.11                                ...           a year ago
  • 0.6.9                                ...           a year ago
  • 0.6.10                                ...           a year ago
  • 0.6.8                                ...           a year ago
  • 0.6.7                                ...           a year ago
  • 0.6.6                                ...           a year ago
  • 0.6.5                                ...           a year ago
  • 0.6.4                                ...           a year ago
  • 0.6.3                                ...           a year ago
  • 0.6.2                                ...           2 years ago
  • 0.6.1                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.3                                ...           2 years ago
  • 0.5.2                                ...           2 years ago
  • 0.5.0                                ...           2 years ago
  • 0.4.8                                ...           2 years ago
  • 0.4.7                                ...           2 years ago
  • 0.4.6                                ...           2 years ago
  • 0.4.5                                ...           2 years ago
  • 0.4.4                                ...           2 years ago
  • 0.4.3                                ...           2 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.4                                ...           3 years ago
  • 0.3.3                                ...           3 years ago
  • 0.3.2                                ...           3 years ago
  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (2)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |