diff --git a/packages/xo-server-auth-github/.editorconfig b/packages/xo-server-auth-github/.editorconfig new file mode 100644 index 000000000..b6db0112a --- /dev/null +++ b/packages/xo-server-auth-github/.editorconfig @@ -0,0 +1,65 @@ +# http://EditorConfig.org +# +# Julien Fontanet's configuration +# https://gist.github.com/julien-f/8096213 + +# Top-most EditorConfig file. +root = true + +# Common config. +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespaces = true + +# CoffeeScript +# +# https://github.com/polarmobile/coffeescript-style-guide/blob/master/README.md +[*.{,lit}coffee] +indent_size = 2 +indent_style = space + +# Markdown +[*.{md,mdwn,mdown,markdown}] +indent_size = 4 +indent_style = space + +# Package.json +# +# This indentation style is the one used by npm. +[/package.json] +indent_size = 2 +indent_style = space + +# Jade +[*.jade] +indent_size = 2 +indent_style = space + +# JavaScript +# +# Two spaces seems to be the standard most common style, at least in +# Node.js (http://nodeguide.com/style.html#tabs-vs-spaces). +[*.{js,jsx,ts,tsx}] +indent_size = 2 +indent_style = space + +# Less +[*.less] +indent_size = 2 +indent_style = space + +# Sass +# +# Style used for http://libsass.com +[*.s[ac]ss] +indent_size = 2 +indent_style = space + +# YAML +# +# Only spaces are allowed. +[*.yaml] +indent_size = 2 +indent_style = space diff --git a/packages/xo-server-auth-github/.gitignore b/packages/xo-server-auth-github/.gitignore new file mode 100644 index 000000000..fa69f37f1 --- /dev/null +++ b/packages/xo-server-auth-github/.gitignore @@ -0,0 +1,5 @@ +/dist/ +/node_modules/ + +npm-debug.log +npm-debug.log.* diff --git a/packages/xo-server-auth-github/.mocha.js b/packages/xo-server-auth-github/.mocha.js new file mode 100644 index 000000000..e6d84e403 --- /dev/null +++ b/packages/xo-server-auth-github/.mocha.js @@ -0,0 +1,5 @@ +Error.stackTraceLimit = 100 + +try { require('trace') } catch (_) {} +try { require('clarify') } catch (_) {} +try { require('source-map-support/register') } catch (_) {} diff --git a/packages/xo-server-auth-github/.mocha.opts b/packages/xo-server-auth-github/.mocha.opts new file mode 100644 index 000000000..6cfd94898 --- /dev/null +++ b/packages/xo-server-auth-github/.mocha.opts @@ -0,0 +1 @@ +--require ./.mocha.js diff --git a/packages/xo-server-auth-github/.npmignore b/packages/xo-server-auth-github/.npmignore new file mode 100644 index 000000000..c31ee82cb --- /dev/null +++ b/packages/xo-server-auth-github/.npmignore @@ -0,0 +1,10 @@ +/examples/ +example.js +example.js.map +*.example.js +*.example.js.map + +/test/ +/tests/ +*.spec.js +*.spec.js.map diff --git a/packages/xo-server-auth-github/.travis.yml b/packages/xo-server-auth-github/.travis.yml new file mode 100644 index 000000000..fb5d91729 --- /dev/null +++ b/packages/xo-server-auth-github/.travis.yml @@ -0,0 +1,8 @@ +language: node_js +node_js: + - 'stable' + - '4' + +# Use containers. +# http://docs.travis-ci.com/user/workers/container-based-infrastructure/ +sudo: false diff --git a/packages/xo-server-auth-github/README.md b/packages/xo-server-auth-github/README.md new file mode 100644 index 000000000..4e36ed3b9 --- /dev/null +++ b/packages/xo-server-auth-github/README.md @@ -0,0 +1,64 @@ +# xo-server-auth-github [![Build Status](https://travis-ci.org/vatesfr/xo-server-auth-github.png?branch=master)](https://travis-ci.org/vatesfr/xo-server-auth-github) + +> GitHub authentication plugin for XO-Server + +This plugin allows GitHub users to authenticate to Xen-Orchestra. + +The first time a user signs in, XO will create a new XO user with the +same identifier. + +## Install + +Installation of the [npm package](https://npmjs.org/package/xo-server-auth-github): + +``` +> npm install --global xo-server-auth-github +``` + +## Usage + +> This plugin is based on [passport-github](https://github.com/jaredhanson/passport-github), +> see [its documentation](https://github.com/jaredhanson/passport-github#configure-strategy) +> for more information about the configuration. + +Like all other xo-server plugins, it can be configured directly via +the web iterface, see [the plugin documentation](https://xen-orchestra.com/docs/plugins.html). + +![Registering XO instance in GitHub](github.png) + +## Development + +### Installing dependencies + +``` +> npm install +``` + +### Compilation + +The sources files are watched and automatically recompiled on changes. + +``` +> npm run dev +``` + +### Tests + +``` +> npm run test-dev +``` + +## Contributions + +Contributions are *very* welcomed, either on the documentation or on +the code. + +You may: + +- report any [issue](https://github.com/vatesfr/xo-server-auth-github/issues) + you've encountered; +- fork and create a pull request. + +## License + +AGPL3 © [Vates SAS](http://vates.fr) diff --git a/packages/xo-server-auth-github/github.png b/packages/xo-server-auth-github/github.png new file mode 100644 index 000000000..b65a59b59 Binary files /dev/null and b/packages/xo-server-auth-github/github.png differ diff --git a/packages/xo-server-auth-github/package.json b/packages/xo-server-auth-github/package.json new file mode 100644 index 000000000..fb7d297d6 --- /dev/null +++ b/packages/xo-server-auth-github/package.json @@ -0,0 +1,80 @@ +{ + "name": "xo-server-auth-github", + "version": "0.2.1", + "license": "AGPL-3.0", + "description": "GitHub authentication plugin for XO-Server", + "keywords": [ + "xo-server", + "xo-server", + "authentication", + "github" + ], + "homepage": "https://github.com/vatesfr/xo-server-auth-github", + "bugs": "https://github.com/vatesfr/xo-server-auth-github/issues", + "repository": { + "type": "git", + "url": "https://github.com/vatesfr/xo-server-auth-github" + }, + "author": { + "name": "Julien Fontanet", + "email": "julien.fontanet@isonoe.net" + }, + "preferGlobal": false, + "main": "dist/", + "bin": {}, + "files": [ + "dist/" + ], + "engines": { + "node": ">=4" + }, + "dependencies": { + "babel-runtime": "^6.11.6", + "passport-github": "^1.1.0" + }, + "devDependencies": { + "babel-cli": "^6.16.0", + "babel-eslint": "^7.0.0", + "babel-plugin-transform-runtime": "^6.15.0", + "babel-preset-latest": "^6.16.0", + "babel-preset-stage-0": "^6.16.0", + "clarify": "^2.0.0", + "dependency-check": "^2.6.0", + "ghooks": "^1.3.2", + "mocha": "^3.1.0", + "must": "^0.13.2", + "source-map-support": "^0.4.3", + "standard": "^8.2.0", + "trace": "^2.3.3" + }, + "scripts": { + "build": "NODE_ENV=production babel --source-maps --out-dir=dist/ src/", + "depcheck": "dependency-check ./package.json", + "dev": "NODE_DEV=development babel --watch --source-maps --out-dir=dist/ src/", + "dev-test": "mocha --opts .mocha.opts --watch --reporter=min \"dist/**/*.spec.js\"", + "lint": "standard", + "posttest": "npm run lint && npm run depcheck", + "prepublish": "npm run build", + "test": "mocha --opts .mocha.opts \"dist/**/*.spec.js\"" + }, + "babel": { + "plugins": [ + "transform-runtime" + ], + "presets": [ + "latest", + "stage-0" + ] + }, + "standard": { + "ignore": [ + "dist" + ], + "parser": "babel-eslint" + }, + "config": { + "ghooks": { + "commit-msg": "npm test" + } + } +} diff --git a/packages/xo-server-auth-github/src/index.js b/packages/xo-server-auth-github/src/index.js new file mode 100644 index 000000000..c427237db --- /dev/null +++ b/packages/xo-server-auth-github/src/index.js @@ -0,0 +1,44 @@ +import {Strategy} from 'passport-github' + +// =================================================================== + +export const configurationSchema = { + type: 'object', + properties: { + clientID: { + type: 'string' + }, + clientSecret: { + type: 'string' + } + }, + required: ['clientID', 'clientSecret'] +} + +// =================================================================== + +class AuthGitHubXoPlugin { + constructor (xo) { + this._xo = xo + } + + configure (conf) { + this._conf = conf + } + + load () { + const {_xo: xo} = this + + xo.registerPassportStrategy(new Strategy(this._conf, async (accessToken, refreshToken, profile, done) => { + try { + done(null, await xo.registerUser('github', profile.username)) + } catch (error) { + done(error.message) + } + })) + } +} + +// =================================================================== + +export default ({xo}) => new AuthGitHubXoPlugin(xo) diff --git a/packages/xo-server-auth-github/src/index.spec.js b/packages/xo-server-auth-github/src/index.spec.js new file mode 100644 index 000000000..2319bd7d5 --- /dev/null +++ b/packages/xo-server-auth-github/src/index.spec.js @@ -0,0 +1,17 @@ +/* eslint-env mocha */ + +import expect from 'must' + +// =================================================================== + +import myLib from './' + +// =================================================================== + +describe.skip('myLib', () => { + it('does something', () => { + // TODO: some real tests. + + expect(myLib).to.exists() + }) +})