ORCID middleware to enable our researchers to designate GW as a trusted partner
- Create your secure key and certificate for SAML encryption/decryption:
openssl req -new -x509 -days 3652 -nodes -out sp.crt -keyout sp.key
- These files should go into an
orcidflask/saml/certs
directory.
- These files should go into an
- In the
orcidflask/saml
directory, create asettings.json
file to provide the metadata for your app and your identity provider, as well as the certificate from your identify provider. You can follow the example on the python3-saml repository or inexample-settings.json
. - Copy the example Flask configuration file and edit it to provide sensitive keys, including the SERVER_KEY, ORCID client ID and ORCID client secret. The
SERVER_KEY
should be the key used to encrypt the Flask session objects, as described here.cp example.config.py config.py
- Copy
example.docker-compose.yml
todocker-compose.yml
andexample.env
to.env
. - Bring up the Docker container(s):
docker-compose up -d
. This will install all necessary dependencies and launch the Flask app with gunicorn on port8080
. For development, comment out the first three lines under thevolumes
section of theflask-app
service and uncomment the line.:/opt/orcid_integration
. This will use the local copy of the Python code. - When the Flask app starts up, it will check for the presence of a database encryption key file (as specified in
example.env
). If the file is not present, it will create a new database encryption key. Be careful with this key. Once the data has been encrypted using it, the key is necessary to decrypt the data again. Loss of the key means loss of the data. - The postgres container will store data outside of the container, in the
./data
directory.- When first run, postgres will set the permissions on this directory to a system user.
- To avoid having the reset permissions on
./data
every time you start up the container, after starting the container the first time, modify thedb
service indocker-compose.yml
to include the following line (whereUID
andGID
are the system ID's of the user and group to which you want to assign ownership of the./data
directory):
user: "UID:GID"
- If you need to provide an XML file to your SAML IdP, with the
flask-app
container running, do the following:The SAML metadata file should be written to thedocker exec -it orcid-integration_flask-app_1 /bin/bash python generate_saml_metadata.xml
orcidflask/saml
directory (bind-mounted outside the container). - For SSL, use gunicorn with nginx:
- Create SSL key and cert (either self-signed or using a certificate authority)
- Install nginx:
sudo apt-get install nginx
- Remove the defaul SSL configuration:
cd /etc/nginx/sites-enabled
sudo rm default
- Create a new nginx configuration to proxy to the Flask app as follows:
server { listen 80; listen [::]:80; server_name gworcid-dev.wrlc.org; return 302 https://$server_name$request_uri; } server { listen 443 ssl; listen [::]:443 ssl; ssl_certificate /etc/ssl/certs/server.crt; ssl_certificate_key /etc/ssl/private/server.key; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header HOST $http_host; proxy_pass http://127.0.0.1:8080; proxy_redirect off; } }
- To quickly serialize the database as a JSON file, you can run the following command (if outside the container), providing the path to a file in a mounted volume:
docker exec -it orcid-integration_flask-app_1 flask serialize-db ./data/token-dump.json