Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit 96a82a6

Browse files
committed
doc clean up
1 parent a4db489 commit 96a82a6

File tree

2 files changed

+27
-208
lines changed

2 files changed

+27
-208
lines changed

README.md

+27-27
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Another hard limit is the size of a session: for Cookies it is restricted to 4kB
3030
As long as you provide a serializer for your custom types, you can use them.
3131
Standard types like `String`, `Integer`, `Long`, `Double` and `Map<String, String>` are supported out of the box.
3232

33-
[Here's an example](https://github.com/softwaremill/akka-http-session-faq/blob/master/src/main/java/session/data_types/StringTypeSession.java) with a `String` data type session:
33+
[Here's an example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/data_types/StringTypeSession.java) with a `String` data type session:
3434
```
3535
$ curl -i --data "a string type" http://localhost:8080/api/do_login
3636
@@ -43,7 +43,7 @@ Content-Length: 2
4343
4444
ok
4545
```
46-
[Here's an example](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/data_types/LongTypeSession.java) with a `Long` data type session:
46+
[Here's an example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/data_types/LongTypeSession.java) with a `Long` data type session:
4747
```
4848
$ curl -i --data "12321" http://localhost:8080/api/do_login
4949
@@ -56,7 +56,7 @@ Content-Length: 2
5656
5757
ok
5858
```
59-
[Here's an example](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/data_types/MapTypeSession.java) with a `Map<String, String>` data type session:
59+
[Here's an example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/data_types/MapTypeSession.java) with a `Map<String, String>` data type session:
6060
```
6161
$ curl -i --data "key1,value1:k2,v2" http://localhost:8080/api/do_login
6262
@@ -80,7 +80,7 @@ Content-Length: 6
8080
value1
8181
```
8282

83-
[Here's an example](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/data_types/CustomTypeSession) with a `CustomType` data type session:
83+
[Here's an example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/data_types/CustomTypeSession) with a `CustomType` data type session:
8484
```
8585
$ curl -i --data "my_login,42" http://localhost:8080/api/do_login
8686
@@ -98,11 +98,11 @@ ok
9898
### How can I transport the session between server and client?
9999
Two transport types are available: Cookies and Headers.
100100

101-
### Why would I use Cookies? {#cookies}
101+
### <a name="cookies"></a>Why would I use Cookies?
102102
Using Cookies to send session data has the advantage that is is handled automatically by client applications, like a web browser.
103103
Also Cookies do not require you to implement a storage, since it's built-in into the browser already.
104104

105-
The [Cookie transport example](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/transport/CookieTransport.java) shows a typical setup for Cookies. Below is a sample use case:
105+
The [Cookie transport example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/transport/CookieTransport.java) shows a typical setup for Cookies. Below is a sample use case:
106106

107107
```
108108
$ curl -i http://localhost:8080/api/current_login
@@ -140,14 +140,14 @@ Content-Length: 8
140140
141141
my_login
142142
```
143-
### Why would I use Headers? {#headers}
143+
### <a name="headers"></a>Why would I use Headers?
144144

145145
Headers are usually used in a non-Cookie world, like mobile.
146146
You need to come up with a storage for the session data on your client application by yourself.
147147
This is what browsers do for you when dealing with Cookies.
148148
Additionally when using refresh tokens, they need to be persisted in that storage as well.
149149

150-
Take a look at [the Header transport example](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/transport/HeaderTransport.java) and how it works:
150+
Take a look at [the Header transport example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/transport/HeaderTransport.java) and how it works:
151151

152152
```
153153
$ curl -i http://localhost:8080/api/current_login
@@ -187,10 +187,10 @@ Content-Length: 8
187187
my_login
188188
```
189189

190-
### How long does a session live? {#max-age}
190+
### <a name="max-age"></a>How long does a session live?
191191
By default a session expires after 1 week, configurable via the `akka.http.session.max-age` config property.
192-
[In this example](https://github.com/akka-http-session-faq/blob/master/src/main/resources/application.com) it is set to 5 minutes.
193-
When running the [HeaderTransport example](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/transport/HeaderTransport.java) we get:
192+
[In this example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/resources/application.conf) it is set to 5 minutes.
193+
When running the [HeaderTransport example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/transport/HeaderTransport.java) we get:
194194
```
195195
$ curl -i --data "my_login" http://localhost:8080/api/do_login
196196
@@ -210,7 +210,7 @@ The timestamp attached to the session is `1505470200180` and translates to `Fri
210210
There is the `OneOff` session which when expired is of no use anymore.
211211
An alternative is the `Refreshable` session.
212212
It will provide the client with an additional `_refreshtoken` Cookie or `Set-Refresh-Token` Header, dependent on the transport type.
213-
The [RefreshableSession](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/continuity/RefreshableSession.java) example shows how to use this type of sessions:
213+
The [RefreshableSession](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/continuity/RefreshableSession.java) example shows how to use this type of sessions:
214214

215215
```
216216
$ curl -i --data "my_login_" http://localhost:8080/api/do_login
@@ -265,7 +265,7 @@ my_login_
265265
### When do I need refreshable sessions?
266266
A refreshable session is typically used for "remember-me" functionality.
267267
This is especially useful in mobile applications, where you log in once, and the session is remembered for a long time.
268-
Make sure to adjust the `akka.http.session.refresh-token.max-age` config property in [application.conf](https://github.com/akka-http-session-faq/blob/master/src/main/resources/application.conf) which defaults to 1 month.
268+
Make sure to adjust the `akka.http.session.refresh-token.max-age` config property in [application.conf](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/resources/application.conf) which defaults to 1 month.
269269
Also, these sessions are persisted.
270270
Although the default implementation stores the refresh tokens in-memory and they won't survive a server restart,
271271
they still can be thought of a way of storing session details on the server side.
@@ -301,7 +301,7 @@ The supplied authentication is not authorized to access this resource
301301

302302
### Is the additional refresh token persistent?
303303
Yes. Therefore using refreshable sessions requires you to implement a storage for these tokens.
304-
An in-memory storage is provided as shown in the [RefreshableSession](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/continuity/RefreshableSession.java) example.
304+
An in-memory storage is provided as shown in the [RefreshableSession](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/continuity/RefreshableSession.java) example.
305305
However using an in-memory database will invalidate all your refresh tokens when the server restarts.
306306

307307
In this example a refresh token is issued and before the second request is sent, the server is restarted:
@@ -341,9 +341,9 @@ This can be either `OneOff` or `Refreshable`.
341341
### Can a Cookie be stolen and be reused by an attacker?
342342
Yes.
343343

344-
### How can I use Cookies in a secure way? {#secure-cookie}
344+
### <a name="secure-cookie"></a>How can I use Cookies in a secure way?
345345
1. Use the `invalidateSession` directive when a user logs out or doesn't need that session any longer.
346-
This is demonstrated by the `do_logout` route in the [CookieTransport example](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/transport/CookieTransport.java).
346+
This is demonstrated by the `do_logout` route in the [CookieTransport example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/transport/CookieTransport.java).
347347
Its purpose is to send an empty `_sessiondata` Cookie to the client (typically a browser).
348348
In consequence, the browser should erase that Cookie to prevent an attacker to read the cookie later on.
349349
```
@@ -364,7 +364,7 @@ It's still possible, that although the browser erased the Cookie, the attacker g
364364
2. Use a sensible `max-age` value which defaults to 7 days
365365
For use cases where it make sense, set the `max-age` property to a low value, for example `5 minutes`.
366366
This is especially true, when your application allows to access sensitive data, like bank accounts, emails, etc.
367-
The `max-age` property is set in `application.conf`, like in [this example](https://github.com/akka-http-session-faq/blob/master/src/main/resources/application.conf).
367+
The `max-age` property is set in `application.conf`, like in [this example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/resources/application.conf).
368368
Using a cookie which expired on `Thu Sep 14 2017 07:38:19` results in a `403` response, when used in a request at `07:39:43`:
369369
```
370370
$ curl -i --cookie "_sessiondata=625617AD3A82A95149B2DAAA6B4444F633F298E5-1505374699373-xmy_login" http://localhost:8080/api/current_login
@@ -387,10 +387,10 @@ It prevents the browser from sending Cookies, if the request is not transmitted
387387
There may be 3 types of Cookies being used in `akka-http-session` and all need to have this option enabled explicitly:
388388
`akka.http.session.cookie.secure`, `csrf.cookie.secure` and `refresh-token.cookie.secure`.
389389

390-
### Even when a session is invalidated by `invalidateSession`, is it still available? {#invalidate-session}
390+
### <a name="invalidate-session"></a>Even when a session is invalidated by `invalidateSession`, is it still available?
391391
Yes.
392392
The invalidation is just a way to inform the client, that it should erase the cookie.
393-
There is not session maintenance going on on the server side.
393+
There is no session maintenance going on on the server side.
394394
This means, a Cookie representing an invalidated session can still be used:
395395
```
396396
$ curl -i --cookie "_sessiondata=625617AD3A82A95149B2DAAA6B4444F633F298E5-1505374699373-xmy_login" http://localhost:8080/api/current_login
@@ -485,7 +485,7 @@ The supplied authentication is not authorized to access this resource
485485

486486
### What does encryption provide me with?
487487
Enabling session data encryption allows to send data in a format that is not readable by the client.
488-
To enable session data encryption set the `akka.http.session.encrypt-data` config property in `application.conf`, like in [this resource file](https://github.com/akka-http-session-faq/blob/master/src/main/resources/application.conf).
488+
To enable session data encryption set the `akka.http.session.encrypt-data` config property in `application.conf`, like in [this resource file](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/resources/application.conf).
489489
As seen below, the client received a token, that can be used to access the secured resource, but the data itself is encrypted.
490490

491491
```
@@ -536,7 +536,7 @@ This directive is responsible for extracting the session result to be used furth
536536
A session result can be `Decoded` (valid), `CreatedFromToken`, `Expired`, `Corrupt` or having no token present `TokenNotFound`
537537
The directive does not require the client to provide a session.
538538
However if a session is present, a result is made available to the server for further processing.
539-
[This example](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/directives/SessionDirective.java) shows two possibilities, either there is no session at all, or the session is present.
539+
[This example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/directives/SessionDirective.java) shows two possibilities, either there is no session at all, or the session is present.
540540
```
541541
$ curl -i --data "session_details" http://localhost:8080/api/do_login
542542
@@ -574,7 +574,7 @@ Content-Length: 15
574574
575575
session_details
576576
```
577-
A more detailed example is available in [VariousSessions.java](https://github.com/softwaremill/akka-http-session/blob/master/example/src/main/java/com/softwaremill/example/session/VariousSessionsJava.java).
577+
A more detailed example is available in [VariousSessions.java](https://github.com/softwaremill/akka-http-session/tree/master/example/src/main/java/com/softwaremill/example/session/VariousSessionsJava.java).
578578

579579
### What is the `invalidateSession` directive good for?
580580
This directive instructs the client to clean the Cookie or Header.
@@ -585,21 +585,21 @@ Take a look at [How can I use Cookies in a secure way?](#secure-cookie) and [Eve
585585
This one is very similar to the `session` directive.
586586
In this case however, we get access to the session details, which is an `Optional`.
587587
Based on that we can decide on the server side, how to proceed.
588-
In the [OptionalSession](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/directives/OptionalSession.java) example, we either reply with `no session` or with the session details, if present.
588+
In the [OptionalSession](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/directives/OptionalSession.java) example, we either reply with `no session` or with the session details, if present.
589589

590590
### What is the `requiredSession` directive good for?
591591
This directive is used to secure endpoints.
592592
Submitting a HTTP request requires the client to provide a valid session.
593593
A session can be requested through an endpoint configured with the `setSession` directive.
594-
The [CookieTransport](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/transport/CookieTransport.java) and [HeaderTransport](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/transport/HeaderTransport.java) examples show how to use this directive.
594+
The [CookieTransport](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/transport/CookieTransport.java) and [HeaderTransport](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/transport/HeaderTransport.java) examples show how to use this directive.
595595
Also a sample use case of securing an endpoint is shown in [the Cookie](#cookies) and [the Header](#headers) transport example.
596596

597597
### What is the `touchRequiredSession` directive good for?
598598
Sessions do expire and the max age is configurable, as mentioned in [How long does a session live?](#max-age).
599599
If you want to expose an endpoint that will reset the expiry date, include the `touchRequiredSession` in the route chain.
600600
Besides the expiry date, the whole token will change.
601601
Again when using Cookies, the browser will handle this, and replace the old Cookie, but in your own client application you have to replace the Cookie or Header by yourself.
602-
This directive is demonstrated in the [TouchRequiredSession](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/directives/TouchRequiredSessionDirective.java) example:
602+
This directive is demonstrated in the [TouchRequiredSession](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/directives/TouchRequiredSessionDirective.java) example:
603603
```
604604
$ curl -i --data "my_login" http://localhost:8080/api/do_login
605605
@@ -660,7 +660,7 @@ In this case the session expired on `1505741661309`, which is `Mon Sep 18 2017 1
660660
## JWT
661661
### How do I use Json Web Tokens
662662
In case you want to use the JWT format for authorization tokens, replace the `BasicSessionEncoder` with the `JwtSessionEncoder` and choose one of the JWT serializers, like `JwtSessionSerializers.StringToJValueSessionSerializer`.
663-
The [JwtEncodedSession](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/jwt/JwtEncodedSession.java) example shows this particular use case:
663+
The [JwtEncodedSession](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/jwt/JwtEncodedSession.java) example shows this particular use case:
664664
```
665665
$ curl -i --data "my_login" http://localhost:8080/api/do_login
666666
@@ -707,7 +707,7 @@ But the attacker is not able to read the cookie value. Hence the attacker is not
707707

708708
### How do I enable CSRF protection
709709
Two directives, `randomTokenCsrfProtection` and `setNewCsrfToken`, are required.
710-
The example [CsrfProtection](https://github.com/akka-http-session-faq/blob/master/src/main/java/session/csrf/CsrfProtection.java) uses both directives.
710+
The example [CsrfProtection](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/csrf/CsrfProtection.java) uses both directives.
711711
Finally a `CheckHeader` component is required to intercept the route and lookup the header for the CSRF token.
712712

713713
The first one, `randomTokenCsrfProtection`, sets a new CSRF token on every GET request in form of a `XSRF-TOKEN` Cookie.

0 commit comments

Comments
 (0)