mirror of
https://github.com/wahyd4/loginsrv.git
synced 2026-08-09 04:46:29 +10:00
Add an example under API Examples
This commit is contained in:
@@ -183,6 +183,29 @@ Location: /
|
||||
Set-Cookie: jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJib2IifQ.-51G5JQmpJleARHp8rIljBczPFanWT93d_N_7LQGUXU; HttpOnly
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user