grant-server v3.1.1
Grant Server
This module is a packaged Grant OAuth proxy server. That means that you can just install this package and run grant-serve to have a proxy OAuth server running.
Install
npm install grant-serverrun it:
grant-serveTable of Contents
How it works
After installing, you will need a grant configuration file to set up different OAuth providers. By default, the module looks for grant.config.json file in the currently executing directory. The server will automatically watch for changes in the configuration file and it will automatically reload.
example configuration file with Google auth:
{
"defaults": {
"origin": "http://localhost:3000",
"prefix": "/oauth"
},
"google": {
"key": "CLIENT_ID",
"secret": "CLIENT_SECRET",
"callback": "https://redirect-user-to-your-app.com",
"scope": ["openid"]
}
}By using the file above we are enabling google OAuth point on http://localhost:3000/oauth/google, and we are asking for OpenID scope. After the tokens have been acquired, the caller will be redirected to https://redirect-user-to-your-app.com with the tokens available via query parameters.
Command line options
-cor--configGrant configuration file. If not provided, by default server will look forgrant.config.jsonin the currently executing directory.-dor--debugEnable writing tokens tostdout. It uses request-logs module. If only the flag is passed it will default tores,jsonotherwise you can customize what the output will be e.g.-d res,req,json,bodypor--proxyBy default internalexpressapp will havetrust proxyflag set totrue. You can pass infalseto disable the proxy. Or use any of the options supported by the express app
Docker image
Docker image is available on docker hub. Image is based on github releases, so it's always up to date.
Docker usage
Pull the image:
docker image pull ivandotv/grant-serverRun the container:
docker run -it -v /config-dir:/opt/grant-server/config-dir ivandotv/grant-server -d -c config/config.jsonFew things to keep in mind when using the docker image.
- Server is started in
/opt/grant-serverdirectory inside the container. - Make sure that the exposed port is the same as in the configuration file.
- If you mount only the external config file:
-v config.json:/opt/grant-server/config.jsonAutomatic reloading of the server will not work, because the server will not see the changes in the file. Better option is to mount the directory where configuration file is located:-v /config-dir:/opt/grant-server/config-dirand then pass the-cflag to the container like so:-c config/config.json.