Example: call the ShinyProxy API using OAuth2
ShinyProxy has an API that can be protected using the OAuth2 authorization framework. This is a complex framework that can be used in many different ways, but in this example the scenario is:
- The user opens a web application (i.e. this example node.js app).
- The user is asked to authenticate with an OAuth2 provider, and to consent to the app accessing the ShinyProxy API on their behalf.
- The OAuth2 provider returns a temporary
authorization code, which this app will exchange for an
- The access token is used to interact with the ShinyProxy API. As long as the access token is valid, it can be used to create, access and stop proxies on the user's behalf.
In this example, the OAuth2 provider Auth0 is used.
How to run
- Set up a ShinyProxy instance (e.g. by following the 01-standalone-docker-engine example).
- Register the ShinyProxy instance with Auth0 as an
- Register this example app with Auth0 as a
Regular Web Application. Don't forget to specify a valid
callback URL, e.g.
- Install node.js.
- Download the files from this git repository into a local folder.
- Review the configuration in the file
app.js, in the variables
- Open a command prompt, navigate to the folder containing the downloaded files, and run
- If you get any dependency errors, install missing modules using
npm install <module-name>.
- Open a browser and navigate to
This example assumes that the ShinyProxy instance runs on
http://localhost:8080. If this is not the case, modify
This example assumes that the node.js app runs on
http://localhost:8081. If this is not the case, modify
If heartbeat is enabled (by default, it is), then the launched proxy will automatically shut down after 1 minute if it is not accessed. Use the settings
heartbeat-timeoutto control this behaviour.