Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/frontend and build preparation #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,81 @@ psql auth_password -U postgres -f ./auth-password/src/main/resources/auth_entry.
psql identity_manager -U postgres -f ./identity-manager/src/main/resources/identity.sql
```

#### Setup CORS proxy

Use NGINX or such to proxy with CORS headers and OPTION request responses.

Crude fast solution:

```
http {
server {
listen 10000;
server_name localhost;
set $true 1;
more_set_headers "Access-Control-Allow-Origin: $http_origin";

location /auth-codecard/ {
proxy_pass http://localhost:8005;
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Headers "Auth-Token, Content-Type";
add_header Access-Control-Allow-Methods "GET, OPTIONS, POST, DELETE, PUT, PATCH";
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
}

location /auth-password/ {
proxy_pass http://localhost:8002;
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Headers "Auth-Token, Content-Type";
add_header Access-Control-Allow-Methods "GET, OPTIONS, POST, DELETE, PUT, PATCH";
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
}
location /auth-fb/ {
proxy_pass http://localhost:8001;
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Headers "Auth-Token, Content-Type";
add_header Access-Control-Allow-Methods "GET, OPTIONS, POST, DELETE, PUT, PATCH";
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
}
location /session/ {
proxy_pass http://localhost:8011;
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Headers "Auth-Token, Content-Type";
add_header Access-Control-Allow-Methods "GET, OPTIONS, POST, DELETE, PUT, PATCH";
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
}
location /btc/ {
proxy_pass http://localhost:8011;
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Headers "Auth-Token, Content-Type";
add_header Access-Control-Allow-Methods "GET, OPTIONS, POST, DELETE, PUT, PATCH, UPGRADE";
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
}
}
}
```


## Running

Before starting anything make sure you have PostgreSQL, MongoDB and Redis up and running.
Expand Down
54 changes: 28 additions & 26 deletions auth-codecard/src/main/scala/AuthCodeCard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,37 @@ object AuthCodeCardCard extends App with JsonProtocols with Config {

Http().bindAndHandle(interface = interface, port = port, handler = {
logRequestResult("auth-codecard") {
(path("register" / "codecard" ) & pathEndOrSingleSlash & post & optionalHeaderValueByName("Auth-Token")) { (tokenValue) =>
complete {
service.register(tokenValue).map[ToResponseMarshallable] {
case Right(response) => Created -> response
case Left(errorMessage) => BadRequest -> errorMessage
pathPrefix("auth-codecard") {
(path("register") & pathEndOrSingleSlash & post & optionalHeaderValueByName("Auth-Token")) { (tokenValue) =>
complete {
service.register(tokenValue).map[ToResponseMarshallable] {
case Right(response) => Created -> response
case Left(errorMessage) => BadRequest -> errorMessage
}
}
}
} ~
(path("login" / "codecard" / "activate") & pathEndOrSingleSlash & post & entity(as[ActivateCodeRequest])) { (request) =>
complete {
service.activateCode(request).map[ToResponseMarshallable] {
case Right(response) => OK -> response
case Left(errorMessage) => BadRequest -> errorMessage
} ~
(path("activate") & pathEndOrSingleSlash & post & entity(as[ActivateCodeRequest])) { (request) =>
complete {
service.activateCode(request).map[ToResponseMarshallable] {
case Right(response) => OK -> response
case Left(errorMessage) => BadRequest -> errorMessage
}
}
}
} ~
(path("login" / "codecard") & pathEndOrSingleSlash & post & optionalHeaderValueByName("Auth-Token") & entity(as[LoginRequest])) { (tokenValue, request) =>
complete {
service.login(request, tokenValue).map[ToResponseMarshallable] {
case Right(response) => Created -> response
case Left(errorMessage) => BadRequest -> errorMessage
} ~
(path("login") & pathEndOrSingleSlash & post & optionalHeaderValueByName("Auth-Token") & entity(as[LoginRequest])) { (tokenValue, request) =>
complete {
service.login(request, tokenValue).map[ToResponseMarshallable] {
case Right(response) => Created -> response
case Left(errorMessage) => BadRequest -> errorMessage
}
}
}
} ~
(path("generate" / "codecard") & pathEndOrSingleSlash & post & optionalHeaderValueByName("Auth-Token") & entity(as[GetCodeCardRequest])) { (tokenValue, request) =>
complete {
service.getCodeCard(request, tokenValue).map[ToResponseMarshallable] {
case Right(response) => OK -> response
case Left(errorMessage) => BadRequest -> errorMessage
} ~
(path("generate") & pathEndOrSingleSlash & post & optionalHeaderValueByName("Auth-Token") & entity(as[GetCodeCardRequest])) { (tokenValue, request) =>
complete {
service.getCodeCard(request, tokenValue).map[ToResponseMarshallable] {
case Right(response) => OK -> response
case Left(errorMessage) => BadRequest -> errorMessage
}
}
}
}
Expand Down
38 changes: 20 additions & 18 deletions auth-fb/src/main/scala/AuthFb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,29 @@ object AuthFb extends App with JsonProtocols with Config {

Http().bindAndHandle(interface = interface, port = port, handler = {
logRequestResult("auth-fb") {
(path("register" / "fb") & pathEndOrSingleSlash & post & entity(as[AuthResponse]) & optionalHeaderValueByName("Auth-Token")) { (authResponse, tokenValue) =>
complete {
service.register(authResponse, tokenValue) match {
case SuccessT(f) => f.map[ToResponseMarshallable] {
case Right(identity) => Created -> identity
case Left(errorMessage) => BadRequest -> errorMessage
pathPrefix("auth-fb") {
(path("register") & pathEndOrSingleSlash & post & entity(as[AuthResponse]) & optionalHeaderValueByName("Auth-Token")) { (authResponse, tokenValue) =>
complete {
service.register(authResponse, tokenValue) match {
case SuccessT(f) => f.map[ToResponseMarshallable] {
case Right(identity) => Created -> identity
case Left(errorMessage) => BadRequest -> errorMessage
}
case FailureT(e: FacebookException) => Unauthorized -> e.getMessage
case _ => InternalServerError
}
case FailureT(e: FacebookException) => Unauthorized -> e.getMessage
case _ => InternalServerError
}
}
} ~
(path("login" / "fb") & pathEndOrSingleSlash & post & entity(as[AuthResponse]) & optionalHeaderValueByName("Auth-Token")) { (authResponse, tokenValue) =>
complete {
service.login(authResponse, tokenValue) match {
case SuccessT(f) => f.map[ToResponseMarshallable] {
case Right(token) => Created -> token
case Left(errorMessage) => BadRequest -> errorMessage
} ~
(path("login") & pathEndOrSingleSlash & post & entity(as[AuthResponse]) & optionalHeaderValueByName("Auth-Token")) { (authResponse, tokenValue) =>
complete {
service.login(authResponse, tokenValue) match {
case SuccessT(f) => f.map[ToResponseMarshallable] {
case Right(token) => Created -> token
case Left(errorMessage) => BadRequest -> errorMessage
}
case FailureT(e: FacebookException) => Unauthorized -> e.getMessage
case _ => InternalServerError
}
case FailureT(e: FacebookException) => Unauthorized -> e.getMessage
case _ => InternalServerError
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions auth-password/src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

akka {
loglevel = DEBUG
}
Expand All @@ -10,7 +11,7 @@ http {
db {
url = "jdbc:postgresql://localhost:5432/auth_password"
user = "postgres"
password = "postgres"
password = ""
}

services {
Expand All @@ -23,4 +24,5 @@ services {
host = "localhost"
port = 8010
}
}
}

58 changes: 30 additions & 28 deletions auth-password/src/main/scala/AuthPassword.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,38 @@ object AuthPassword extends App with JsonProtocols with Config {

Http().bindAndHandle(interface = interface, port = port, handler = {
logRequestResult("auth-password") {
path("register" / "password") {
(pathEndOrSingleSlash & post & entity(as[PasswordRegisterRequest]) & optionalHeaderValueByName("Auth-Token")) {
(request, tokenValue) =>
complete {
service.register(request, tokenValue).map[ToResponseMarshallable] {
case Right(identity) => Created -> identity
case Left(errorMessage) => BadRequest -> errorMessage
}
pathPrefix("auth-password") {
path("register") {
(pathEndOrSingleSlash & post & entity(as[PasswordRegisterRequest]) & optionalHeaderValueByName("Auth-Token")) {
(request, tokenValue) =>
complete {
service.register(request, tokenValue).map[ToResponseMarshallable] {
case Right(identity) => Created -> identity
case Left(errorMessage) => BadRequest -> errorMessage
}
}
}
}
} ~
path("login" / "password") {
(pathEndOrSingleSlash & post & entity(as[PasswordLoginRequest]) & optionalHeaderValueByName("Auth-Token")) {
(request, tokenValue) =>
complete {
service.login(request, tokenValue).map[ToResponseMarshallable] {
case Right(token) => Created -> token
case Left(errorMessage) => BadRequest -> errorMessage
}
}
}
} ~
path("reset" / "password") {
(pathEndOrSingleSlash & post & entity(as[PasswordResetRequest]) & headerValueByName("Auth-Token")) {
(request, tokenValue) =>
complete {
service.reset(request, tokenValue).map[ToResponseMarshallable] {
case Right(identity) => OK -> identity
case Left(errorMessage) => BadRequest -> errorMessage
} ~
path("login") {
(pathEndOrSingleSlash & post & entity(as[PasswordLoginRequest]) & optionalHeaderValueByName("Auth-Token")) {
(request, tokenValue) =>
complete {
service.login(request, tokenValue).map[ToResponseMarshallable] {
case Right(token) => Created -> token
case Left(errorMessage) => BadRequest -> errorMessage
}
}
}
} ~
path("reset") {
(pathEndOrSingleSlash & post & entity(as[PasswordResetRequest]) & headerValueByName("Auth-Token")) {
(request, tokenValue) =>
complete {
service.reset(request, tokenValue).map[ToResponseMarshallable] {
case Right(identity) => OK -> identity
case Left(errorMessage) => BadRequest -> errorMessage
}
}
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ version := "1.0"

lazy val `reactive-microservices` = (project in file("."))

lazy val `frontend-server` = project in file("frontend-server")

lazy val metricsCommon = project in file("metrics-common")

Expand Down Expand Up @@ -42,7 +41,6 @@ val cleanAll = taskKey[Unit]("Cleans all subprojects")
compileAll := {
fork in compile := true

(compile in Compile in `frontend-server`).toTask.value
(compile in Compile in `token-manager`).toTask.value
(compile in Compile in `session-manager`).toTask.value
(compile in Compile in `identity-manager`).toTask.value
Expand All @@ -53,7 +51,6 @@ compileAll := {
}

cleanAll := {
(clean in Compile in `frontend-server`).toTask.value
(clean in Compile in `token-manager`).toTask.value
(clean in Compile in `session-manager`).toTask.value
(clean in Compile in `identity-manager`).toTask.value
Expand All @@ -65,7 +62,6 @@ cleanAll := {


runAll := {
(run in Compile in `frontend-server`).evaluated
(run in Compile in `token-manager`).evaluated
(run in Compile in `session-manager`).evaluated
(run in Compile in `identity-manager`).evaluated
Expand Down
22 changes: 0 additions & 22 deletions frontend-server/build.sbt

This file was deleted.

1 change: 0 additions & 1 deletion frontend-server/project/plugins.sbt

This file was deleted.

12 changes: 0 additions & 12 deletions frontend-server/src/main/resources/application.conf

This file was deleted.

18 changes: 0 additions & 18 deletions frontend-server/src/main/scala/FrontendServer.scala

This file was deleted.

Loading