https://github.com/mdedetrich/censored-raw-header
A RawHeader which can be used for akka-http that allows you to censor the .toString method
https://github.com/mdedetrich/censored-raw-header
actors akka akka-http http logging oauth2 token
Last synced: about 2 months ago
JSON representation
A RawHeader which can be used for akka-http that allows you to censor the .toString method
- Host: GitHub
- URL: https://github.com/mdedetrich/censored-raw-header
- Owner: mdedetrich
- License: other
- Created: 2017-05-23T15:28:08.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-07-15T14:01:01.000Z (almost 5 years ago)
- Last Synced: 2025-01-08T18:29:46.142Z (over 1 year ago)
- Topics: actors, akka, akka-http, http, logging, oauth2, token
- Language: Scala
- Size: 23.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/mdedetrich/censored-raw-header/actions)
[](https://index.scala-lang.org/mdedetrich/censored-raw-header)
[](https://opensource.org/licenses/BSD-2-Clause)
## Censored Raw Header
Censored raw header is a simple implementation of `RawHeader` which allows you to provide
a custom `.toString` method. This is useful when it comes to censoring log output of headers of
sensitive information, such as OAuth2 tokens.
## Usage
Put this into your `build.sbt`
```scala
libraryDependencies ++= Seq(
"org.mdedetrich" %% "censored-raw-header" % "0.7.0"
)
```
Then simply created your own custom `CensoredRawHeader`, i.e. if you want to store an OAuth2
token with implicit flow you might do the following
```scala
import akka.http.scaladsl.model.headers.CensoredRawHeader
val token: String = ??? // Some Token
CensoredRawHeader("Authorization",
s"Bearer $token",
s"Bearer ${token.take(3)}...${token.takeRight(3)}")
```
This means that when someone accesses the raw value from within the `CensoredRawHeader` they will
get the actual value, however if they call `.toString` on the `CensoredRawHeader` (or any data
structure containing the `CensoredRawHeader`) it will print the first 3 characters of the token, then `...` and then
the last 3 values of the token