Skip to content

Commit

Permalink
Merge pull request #78 from magikstm/API-Example-1
Browse files Browse the repository at this point in the history
Add a new example under "API Examples"
  • Loading branch information
Sebastian Mancke authored Mar 14, 2018
2 parents 449987a + 74e3fca commit bf6909d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bf6909d

Please sign in to comment.