loginsrv

Unnamed repository; edit this file 'description' to name the repository.
git clone git@jamesshield.xyz:repos/loginsrv.git
Log | Files | Refs | README | LICENSE

commit bf6909d19dbac7452f1e4584e9d7b20030fe1471
parent 449987a7eb87e17afa380e5c8395bfb5fe21121c
Author: Sebastian Mancke <s.mancke@tarent.de>
Date:   Wed, 14 Mar 2018 09:22:35 +0100

Merge pull request #78 from magikstm/API-Example-1

Add a new example under "API Examples"
Diffstat:
MREADME.md | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -183,6 +183,30 @@ Location: / Set-Cookie: jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJib2IifQ.-51G5JQmpJleARHp8rIljBczPFanWT93d_N_7LQGUXU; HttpOnly ``` +#### Example: AJAX call with JQuery to fetch a JWT token and create a cookie from it +Creates a cookie from a successful API call to login. +``` +$.ajax({ + url: "http://localhost:8080/login", + type: 'POST', + dataType: 'text', + contentType: 'application/json', + data: JSON.stringify( { + 'username': 'demo', + 'password': 'demo' + }), + success: function(data) { + document.cookie = "jwt_token=" + data + ";path=/"; + }, + error: function (xhr, ajaxOptions, thrownError) { + } +}); +``` +Make sure your main page has JQuery: +``` +<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> +``` + ### Redirects The API has support for a redirect query parameter, e.g. `?backTo=/dynamic/return/path`. For security reasons, the default behaviour is very restrictive: