YOU ARE DOWNLOADING DOCUMENT

Please tick the box to continue:

Transcript
Page 1: Authentication and Authorization Architecture in the MEAN Stack

5 Authentication AuthorizationArchitecturein Browser Applications

Yuri Takhteyev, rangle.iohttp://yto.io@qaramazov

+

Page 2: Authentication and Authorization Architecture in the MEAN Stack

Authenticate,Authorize

Page 3: Authentication and Authorization Architecture in the MEAN Stack

Protectingclients from:

outsiders

each other

themselves

Page 4: Authentication and Authorization Architecture in the MEAN Stack

Display and capture

Authentication

Business logic

Storage

Interaction logic

Interaction logic

AuthorizationServer

Client

Page 5: Authentication and Authorization Architecture in the MEAN Stack

Display and capture

Authentication

Business logic

Storage

Interaction logic

Authorization

Business logic

Authentication

Authorization

Authorization

Page 6: Authentication and Authorization Architecture in the MEAN Stack

Display and capture

Business logic

Storage

Interaction logic

Authorization

Business logic

Authentication

Authorization

Authorization :-(

Authorization :-)

Page 7: Authentication and Authorization Architecture in the MEAN Stack

Who am I?

Cookies vs tokens

Maintaining the state

Page 8: Authentication and Authorization Architecture in the MEAN Stack

Passport Local

Social / OAuth

Page 9: Authentication and Authorization Architecture in the MEAN Stack

Many Faces of Authorization

By role or activity

By resource instance

Altogether custom

Page 10: Authentication and Authorization Architecture in the MEAN Stack

Bottlenecks

Page 11: Authentication and Authorization Architecture in the MEAN Stack
Page 12: Authentication and Authorization Architecture in the MEAN Stack

Setting Up an API Route

var mapper = koast.makeMongoMapper(connection);

routes = [ ['get', 'robots', user.any, mapper.get('robots', []) ], ['put', 'robots/:robotNumber', user.any, mapper.put('robots', ['robotNumber']) ]];

Page 13: Authentication and Authorization Architecture in the MEAN Stack

Restricting Access by Object

mapper.queryDecorator = function(query, req, res) { query.owner = req.user.username;};

mapper.queryDecorator = function(query, req, res) { query.clientId = req.user.clientId;};

Page 14: Authentication and Authorization Architecture in the MEAN Stack

Post-Query Filtering

mapper.filter = function(result, req) { if (req.method === 'GET' { return canSee(data, req); } else { return canEdit(data, req); }};

Page 15: Authentication and Authorization Architecture in the MEAN Stack

Informing the Client

mapper.clientAuthorizer = function(result, req, res) { result.meta.can.edit = canEdit(result.data, req);};

Page 16: Authentication and Authorization Architecture in the MEAN Stack

The Client Side

angular.module('sampleKoastClientApp', ['koast'])

.controller('myCtrl', ['$scope', 'koast', '$log', function($scope, koast, $log) {

$scope.login = function(provider) { koast.user.initiateOauthAuthentication( provider); };

...

Page 17: Authentication and Authorization Architecture in the MEAN Stack

The Client Side

...

koast.user.getStatusPromise() .then(function() { if (koast.user.isAuthenticated) { return koast.getResource('robots') .then(function(robots) { $scope.robots = robots; }); } }) .then(null, $log.error);}]);

Page 18: Authentication and Authorization Architecture in the MEAN Stack

The Template

<span ng-if="robot.can.edit"> <button>...</button></span>

Page 19: Authentication and Authorization Architecture in the MEAN Stack

Thank You.Contact: [email protected] http://yto.io @qaramazov

This presentation: http://yto.io/auth

Koast: http://yto.io/koast


Related Documents