Merge remote-tracking branch 'xo-server-auth-google/master'

This commit is contained in:
Julien Fontanet 2017-10-05 17:42:11 +02:00
commit 585b943a52
11 changed files with 3880 additions and 0 deletions

View File

@ -0,0 +1,24 @@
/benchmark/
/benchmarks/
*.bench.js
*.bench.js.map
/examples/
example.js
example.js.map
*.example.js
*.example.js.map
/fixture/
/fixtures/
*.fixture.js
*.fixture.js.map
*.fixtures.js
*.fixtures.js.map
/test/
/tests/
*.spec.js
*.spec.js.map
__snapshots__/

View File

@ -0,0 +1,9 @@
language: node_js
node_js:
- stable
- 6
- 4
# Use containers.
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false

View File

@ -0,0 +1,77 @@
# xo-server-auth-google [![Build Status](https://travis-ci.org/vatesfr/xen-orchestra.png?branch=master)](https://travis-ci.org/vatesfr/xen-orchestra)
> Google authentication plugin for XO-Server
This plugin allows Google 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-google):
```
> npm install --global xo-server-auth-google
```
## Usage
> This plugin is based on [passport-google](https://google.com/jaredhanson/passport-google),
> see [its documentation](https://google.com/jaredhanson/passport-google#configure-strategy)
> for more information about the configuration.
### Creating the Google project
[Create a new project](https://console.developers.google.com/project):
![](create-project.png)
![](create-project-2.png)
Enable the Google+ API:
![](enable-google+-api.png)
Add OAuth 2.0 credentials:
![](add-oauth2-credentials.png)
![](add-oauth2-credentials-2.png)
### Add the plugin to XO-Server config
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).
## Development
```
# Install dependencies
> npm install
# Run the tests
> npm test
# Continuously compile
> npm run dev
# Continuously run the tests
> npm run dev-test
# Build for production (automatically called by npm install)
> npm run build
```
## Contributions
Contributions are *very* welcomed, either on the documentation or on
the code.
You may:
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
you've encountered;
- fork and create a pull request.
## License
AGPL3 © [Vates SAS](http://vates.fr)

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -0,0 +1,99 @@
{
"name": "xo-server-auth-google",
"version": "0.2.0",
"license": "AGPL-3.0",
"description": "Google authentication plugin for XO-Server",
"keywords": [
"authentication",
"google",
"orchestra",
"plugin",
"xen",
"xen-orchestra",
"xo-server"
],
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/packages/xo-server-auth-google",
"bugs": "https://github.com/vatesfr/xo-web/issues",
"repository": {
"type": "git",
"url": "https://github.com/vatesfr/xen-orchestra.git"
},
"author": {
"name": "Julien Fontanet",
"email": "julien.fontanet@isonoe.net"
},
"preferGlobal": false,
"main": "dist/",
"bin": {},
"files": [
"dist/"
],
"engines": {
"node": ">=4"
},
"dependencies": {
"babel-runtime": "^6.23.0",
"passport-google-oauth20": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.1",
"babel-plugin-lodash": "^3.2.11",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.3.3",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^4.0.0",
"dependency-check": "^2.8.0",
"husky": "^0.13.3",
"jest": "^19.0.2",
"rimraf": "^2.6.1",
"standard": "^10.0.1"
},
"scripts": {
"build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/",
"commitmsg": "npm test",
"dev": "cross-env NODE_ENV=development babel --watch --source-maps --out-dir=dist/ src/",
"dev-test": "jest --bail --watch",
"posttest": "standard && dependency-check ./package.json",
"prebuild": "rimraf dist/",
"predev": "npm run prebuild",
"prepublish": "npm run build",
"test": "jest"
},
"babel": {
"env": {
"test": {
"ignore": null
}
},
"ignore": "*.spec.js",
"plugins": [
"transform-runtime",
"lodash"
],
"presets": [
[
"env",
{
"targets": {
"node": 4
}
}
],
"stage-3"
]
},
"jest": {
"testEnvironment": "node",
"roots": [
"<rootDir>/src"
],
"testRegex": "\\.spec\\.js$"
},
"standard": {
"ignore": [
"dist"
],
"parser": "babel-eslint"
}
}

View File

@ -0,0 +1,61 @@
import { Strategy } from 'passport-google-oauth20'
// ===================================================================
export const configurationSchema = {
type: 'object',
properties: {
callbackURL: {
type: 'string',
description: 'Must be exactly the same as specified on the Google developer console.'
},
clientID: {
type: 'string'
},
clientSecret: {
type: 'string'
},
scope: {
default: 'https://www.googleapis.com/auth/plus.login',
description: 'Note that changing this value will break existing users.',
enum: [ 'https://www.googleapis.com/auth/plus.login', 'email' ],
enumNames: [ 'Google+ name', 'Simple email address' ]
}
},
required: ['callbackURL', 'clientID', 'clientSecret']
}
// ===================================================================
class AuthGoogleXoPlugin {
constructor ({ xo }) {
this._conf = null
this._xo = xo
}
configure (conf) {
this._conf = conf
}
load () {
const conf = this._conf
const xo = this._xo
xo.registerPassportStrategy(new Strategy(conf, async (accessToken, refreshToken, profile, done) => {
try {
done(null, await xo.registerUser(
'google',
conf.scope === 'email'
? profile.emails[0].value
: profile.displayName
))
} catch (error) {
done(error.message)
}
}))
}
}
// ===================================================================
export default opts => new AuthGoogleXoPlugin(opts)

File diff suppressed because it is too large Load Diff