0.1.13 • Published 6 years ago

ndx-auth v0.1.13

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

ndx-auth

oauth2 user authentication for ndx-framework

install with
npm install --save ndx-auth

what it does

ndx-auth adds a post route /auth/token to your app, calling this with a valid base64 encoded Basic Authentication header will provide an accessToken which can then be used to connect to the app.

Example

src/server/app.coffee

require 'ndx-server'
.config
  database: 'db'
.use 'ndx-cors'
.use 'ndx-user-roles'
.use 'ndx-auth'
.use 'ndx-superadmin'
.controller (ndx) ->
  ndx.app.get '/api/protected', ndx.authenticate('superadmin'), (req, res, next) ->
    res.json res.user
.start()

connector.coffee

$scope.username = 'superadmin@admin.com'
$scope.password = 'admin'
user = "#{$scope.username}:#{$scope.password}"
$http.defaults.headers.common['Authorization'] = 'Basic ' + base64.encode(user)
$http.post 'http://localhost:3000/auth/token'
.then (response) ->
  if response.data and response.data.accessToken
    $http.defaults.headers.common['Authorization'] = 'Bearer ' + response.data.accessToken
    #all api calls will now be authenticated
    $http.get 'http://localhost:3000/api/protected'
    .then (response) ->
      console.log response.data
0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago