Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jcavat/akka-http-mongodb-cors
https://github.com/jcavat/akka-http-mongodb-cors
akka-http bearer-authentication cors-request docker docker-compose mongodb oauth2 scala snippet template
Last synced: 12 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jcavat/akka-http-mongodb-cors
- Owner: jcavat
- Created: 2019-03-07T15:02:31.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-06T19:59:37.000Z (over 5 years ago)
- Last Synced: 2024-11-17T15:56:17.977Z (2 months ago)
- Topics: akka-http, bearer-authentication, cors-request, docker, docker-compose, mongodb, oauth2, scala, snippet, template
- Language: Scala
- Size: 6.84 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Akka-http snippet with OAuth2 Bearer + CORS + MongoDB
## Summary
This snippet is based on [https://github.com/jcavat/akka-http-with-bearer-tokens](https://github.com/jcavat/akka-http-with-bearer-tokens)
We use OAuth2 baerer to authenticate + CORS + MongoDB database to persist data
The list of credentials are given in the `application.conf` file in `src/main/resources` folder. MongoDB credentials
must be those declared in `docker-compose.yml` file.The documents to get/post/persist are defined as case classes :
```
final case class User(_id: Option[ObjectId], name: String, email: String, tags: List[Tag])
final case class Tag(name: String)
```Run mongodb with docker-compose:
```
docker-compose up -d
```Create `db-users` database and `users` collection with mongo-express at [http://localhost:8081](http://localhost:8081)
Run the server with `sbt run` and try:
post some users :
```
curl -H "Content-Type: application/json" -H "Authorization: Bearer ABCD" http://localhost:8080/users -X POST -d '{"name": "asdf", "email": "[email protected]", "tags": [{"name": "youpie"}, {"name": "haha"}]}'
curl -H "Content-Type: application/json" -H "Authorization: Bearer ABCD" http://localhost:8080/users -X POST -d '{"name": "tutu", "email": "[email protected]", "tags": []}'
```get all users:
```
curl -H "Content-Type: application/json" -H "Authorization: Bearer ABCD" http://localhost:8080/users
```