Skip to content

Instantly share code, notes, and snippets.

@tingletech
Last active March 4, 2016 02:37
Show Gist options
  • Save tingletech/011059ca25d72104633d to your computer and use it in GitHub Desktop.
Save tingletech/011059ca25d72104633d to your computer and use it in GitHub Desktop.

~/.pynuxrc

pynux and nxcli use the same config file format

since the configuration contains access credientials for Nuxeo, it is a good practice to make the file so that it can only be read by the current user, espcialy on multiuser systems. In unix, run this command. (other platforms...?)

chmod 600 ~/.pynuxrc

Basic authentication and token authentication are both supported.

Auth Token

[nuxeo_account]
method = token
X-Authentication-Token = xxx

[rest_api]
; pynux
base = https://nuxeo.cdlib.org/Nuxeo/site/api/v1
; js nxcli nuxeo-js-client
baseURL = https://nuxeo.cdlib.org/Nuxeo/
X-NXDocumentProperties = dublincore,ucldc_schema,picture

ucldc docs ☞ token authentication

Basic auth

[nuxeo_account]
user = api_username
password = 

[rest_api]
; pynux
base = https://nuxeo.cdlib.org/Nuxeo/site/api/v1
; js nxcli nuxeo-js-client
baseURL = https://nuxeo.cdlib.org/Nuxeo/
X-NXDocumentProperties = dublincore,ucldc_schema,picture

Contact oacops@cdlib.org if you have a use case that requires basic auth.

#!/usr/bin/env bash
urlencode() {
# urlencode <string>
# Chris Down https://gist.github.com/cdown/1163649
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%s' "$c" | xxd -p -c1 |
while read c; do printf '%%%s' "$c"; done ;;
esac
done
}
# https://nuxeo.cdlib.org/nuxeo/authentication/token?applicationName=API+ACCESS&deviceId=&deviceDescription=&permission=rw
deviceId=$(hostname)
applicationName='CDL_API_ACCESS'
echo "device description (what machine is this key for?)"
read device
deviceDescription=$(urlencode "$device")
echo "permission"
select permission in r rw;
do
if [[ $permission ]]; then
break
fi
done
echo "https://nuxeo.cdlib.org/nuxeo/authentication/token?applicationName=$applicationName&deviceId=$deviceId&deviceDescription=$deviceDescription&permission=$permission"
https://nuxeo.cdlib.org/nuxeo/authentication/token?applicationName=API+ACCESS&deviceId=&deviceDescription=&permission=rw
You can manage tokens under "Nuxeo Drive > Authentication tokens"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment