RocketChat/rocketchat-oauth2-server

Name: rocketchat-oauth2-server

Owner: Rocket.Chat

Description: OAuth 2 Server package

Created: 2015-12-31 18:43:28.0

Updated: 2017-12-13 02:46:43.0

Pushed: 2017-03-31 20:03:14.0

Homepage: null

Size: 16

Language: CoffeeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

oauth2-server

This package is a implementation of the package node-oauth2-server for Meteor.

It implements the authorization_code and works like the Facebook's OAuth popup.

Install
or add rocketchat:oauth2-server
Implementation
Server implementation

server/oauth2server.js

oauth2server = new OAuth2Server({
 You can change the collection names, the values
 below are the default values.
cessTokensCollectionName: 'oauth_access_tokens',
freshTokensCollectionName: 'oauth_refresh_tokens',
ientsCollectionName: 'oauth_clients',
thCodesCollectionName: 'oauth_auth_codes',
 You can pass the collection object too
 accessTokensCollection: new Meteor.Collection('custom_oauth_access_tokens'),
 refreshTokensCollection: new Meteor.Collection('custom_oauth_refresh_tokens'),
 clientsCollection: new Meteor.Collection('custom_oauth_clients'),
 authCodesCollection: new Meteor.Collection('custom_oauth_auth_codes'),
 You can enable some logs too
bug: true


dd the express routes of OAuth before the Meteor routes
pp.rawConnectHandlers.use(oauth2server.app);

dd a route to return account information
h2server.routes.get('/account', oauth2server.oauth.authorise(), function(req, res, next) {
r user = Meteor.users.findOne(req.user.id);

s.send({
id: user._id,
name: user.name
;

Client/Pupup implementation

client/authorize.js

efine the route to render the popup view
Router.route('/oauth/authorize', {
tion: function(params, queryParams) {
BlazeLayout.render('authorize', queryParams);



ubscribe the list of already authorized clients
o auto accept
late.authorize.onCreated(function() {
is.subscribe('authorizedOAuth');


et the login token to pass to oauth
his is the best way to identify the logged user
late.authorize.helpers({
tToken: function() {
return localStorage.getItem('Meteor.loginToken');



uto click the submit/accept button if user already
ccepted this client
late.authorize.onRendered(function() {
r data = this.data;
is.autorun(function(c) {
var user = Meteor.user();
if (user && user.oauth && user.oauth.authorizedClients && user.oauth.authorizedClients.indexOf(data.client_id()) > -1) {
  c.stop();
  $('button').click();
}
;

client/authorize.html

plate name="authorize">
#if currentUser}}
<form method="post" action="" role="form" class="{{#unless Template.subscriptionsReady}}hidden{{/unless}}">
  <h2>Authorise</h2>
  <input type="hidden" name="allow" value="yes">
  <input type="hidden" name="token" value="{{getToken}}">
  <input type="hidden" name="client_id" value="{{client_id}}">
  <input type="hidden" name="redirect_uri" value="{{redirect_uri}}">
  <input type="hidden" name="response_type" value="code">
  <button type="submit">Authorise</button>
</form>
{{#unless Template.subscriptionsReady}}
  loading...
{{/unless}}
else}}
{{> loginButtons}}
/if}}
mplate>

client/style.css

den {
splay: none;


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.