Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document example a few example API requests #37

Open
britton-jb opened this issue Mar 7, 2017 · 4 comments
Open

Document example a few example API requests #37

britton-jb opened this issue Mar 7, 2017 · 4 comments

Comments

@britton-jb
Copy link
Owner

Document example API authentication, and authenticated request after authentication for those not familiar with the way Guardian works.

@sgeos
Copy link

sgeos commented May 18, 2017

Is there a way to POST login information and get a token back via the API? It seems like an older version of Sentinel had that functionality, although I may have hand rolled it. In any case, it seems like a reasonable thing to provide out of the box.

@britton-jb
Copy link
Owner Author

Looks like in v2 with the Ueberauth addition I must have removed that. I'll work on adding that back in. In the meantime you should be able to achieve that by posting to /auth/session.

Sorry about that oversight.

@sgeos
Copy link

sgeos commented May 19, 2017

I look forward to a resolution to this regression.

Just in case anyone else runs into this problem, something like the following can be used to get a guardian token from the command line by posting to /auth/session.

EMAIL=me@example.com
PASSWORD=my_password
HOST=http://localhost:8080
COOKIE_FILE=$(mktemp /tmp/api_auth_session_html.cookie.XXXXXX)
curl -s -c "${COOKIE_FILE}" -X POST -F "session[email]=${EMAIL}" -F "session[password]=${PASSWORD}" "${HOST}/auth/session" 2>/dev/null > /dev/null
curl -s -b "${COOKIE_FILE}" -X GET "${HOST}" | grep guardian_token | sed -e 's/^.*content="//g' | sed -e 's/".*$//g'
rm -f "${COOKIE_FILE}"

@britton-jb
Copy link
Owner Author

Forgot about this one during my review process. I'll add it to the features/lockable_and_plug branch changes, which include a number of other changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants