-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for handling a CSRF token to pass-data-client
- Loading branch information
1 parent
f7bf2ef
commit f8669c8
Showing
2 changed files
with
41 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
pass-data-client/src/main/java/org/eclipse/pass/support/client/OkHttpCsrfInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.eclipse.pass.support.client; | ||
|
||
import java.io.IOException; | ||
|
||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
/** | ||
* Add CSRF token as a header and cookie to requests. | ||
* The token can have any value. | ||
*/ | ||
public class OkHttpCsrfInterceptor implements Interceptor { | ||
private static String CSRF_TOKEN = "anyvalue"; | ||
|
||
@Override | ||
public Response intercept(Chain chain) throws IOException { | ||
Request request = chain.request().newBuilder().header("X-XSRF-TOKEN", CSRF_TOKEN) | ||
.header("Cookie", "XSRF-TOKEN=" + CSRF_TOKEN).build(); | ||
|
||
return chain.proceed(request); | ||
} | ||
} |