Skip to content

Commit

Permalink
Merge pull request #247 from MadAppGang/refacotr_auth_web_app
Browse files Browse the repository at this point in the history
Refactor auth web app
  • Loading branch information
erudenko authored Oct 15, 2021
2 parents 51b200d + dbacff2 commit 24ca815
Show file tree
Hide file tree
Showing 746 changed files with 72,776 additions and 43,213 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ integrations/*/*/master.zip
integrations/aws/identifo lambda/.env
.devcontainer

web_apps_src/web-element/cypress/screenshots/*
static/admin_panel
static/web/element/**

.idea
db3.db
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
FROM node:16 as node_builder

WORKDIR /identifo
COPY web_apps_src ./web_apps_src
COPY static ./static
RUN web_apps_src/update-admin.sh
RUN web_apps_src/update-web.sh


FROM golang:1.16-alpine3.13 as builder

# Copy the code from the host and compile it
Expand All @@ -11,7 +20,6 @@ RUN apk --no-cache add ca-certificates

WORKDIR /root/
COPY --from=builder /identifo .

COPY static ./static
COPY --from=node_builder /identifo/static ./static

ENTRYPOINT ["./identifo"]
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,23 @@ build:

lint:
golangci-lint run -D deadcode,errcheck,unused,varcheck,govet

build_admin_panel:
rm -rf static/admin_panel
web_apps_src/update-admin.sh

build_login_web_app:
rm -rf static/web/element
web_apps_src/update-web.sh

build_web: build_admin_panel build_login_web_app


run_ui_tests:
go run main.go --config=file://./cmd/config-boltdb.yaml &
cd web_apps_src/web-element && npx cypress run
kill $$(ps | grep config-boltdb.yaml | awk '{print $1}')

open_ui_tests:
$$(cd web_apps_src/web-element; npm install; $$(npm bin)/cypress open )

97 changes: 83 additions & 14 deletions cmd/config-boltdb.yaml
Original file line number Diff line number Diff line change
@@ -1,58 +1,127 @@
general: # General server settings.
port: 8081
host: http://localhost:8081 # Identifo server URL. If "HOST_NAME" env variable is set, it overrides the value specified here.
issuer: http://localhost # JWT tokens issuer.

general:
host: http://localhost:8081
port: "8081"
issuer: http://localhost
supported_scopes: []
adminAccount:
loginEnvName: IDENTIFO_ADMIN_LOGIN
passwordEnvName: IDENTIFO_ADMIN_PASSWORD

storage:
appStorage:
type: boltdb
boltdb:
path: ./db.db
mongo:
connection: ""
database: ""
dynamo:
region: ""
endpoint: ""
userStorage:
type: boltdb
boltdb:
path: ./db.db
mongo:
connection: ""
database: ""
dynamo:
region: ""
endpoint: ""
tokenStorage:
type: boltdb
boltdb:
path: ./db.db
mongo:
connection: ""
database: ""
dynamo:
region: ""
endpoint: ""
tokenBlacklist:
type: boltdb
boltdb:
path: ./db.db
mongo:
connection: ""
database: ""
dynamo:
region: ""
endpoint: ""
verificationCodeStorage:
type: boltdb
boltdb:
path: ./db.db
mongo:
connection: ""
database: ""
dynamo:
region: ""
endpoint: ""
inviteStorage:
type: boltdb
boltdb:
path: ./db.db
mongo:
connection: ""
database: ""
dynamo:
region: ""
endpoint: ""
sessionStorage:
type: memory
sessionDuration: 300
static:
type: local
local:
folder: ./static
serveAdminPanel: true
redis:
address: ""
password: ""
db: 0
dynamo:
region: ""
endpoint: ""
services:
email:
type: mock
mailgun:
domain: ""
privateKey: ""
publicKey: ""
sender: ""
ses:
region: ""
sender: ""
sms:
type: mock
twilio:
accountSid: ""
authToken: ""
serviceSid: ""
nexmo:
apiKey: ""
apiSecret: ""
routemobile:
username: ""
password: ""
source: ""
region: ""
login:
loginWith:
username: true
phone: true
username: false
phone: false
email: false
federated: true
federated: false
tfaType: app
keyStorage:
type: local
s3:
region: ""
bucket: ""
private_key_key: ""
file:
private_key_path: ./jwt/test_artifacts/private.pem
logger:
dumpRequest: false
adminPanel:
enabled: true
loginWebApp:
type: none
emailTemplaits:
type: none
2 changes: 2 additions & 0 deletions cmd/config-dynamodb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ services:
type: mock
sms:
type: mock
adminPanel:
enabled: true
2 changes: 2 additions & 0 deletions cmd/config-mem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ services:
type: mock
sms:
type: mock
adminPanel:
enabled: true
2 changes: 2 additions & 0 deletions cmd/config-mongodb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ services:
type: mock
sms:
type: mock
adminPanel:
enabled: true
54 changes: 50 additions & 4 deletions config/configurator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"io/fs"

"github.com/madappgang/identifo/model"
"github.com/madappgang/identifo/server"
"github.com/madappgang/identifo/services/mail"
Expand All @@ -10,6 +12,27 @@ import (
jwt "github.com/madappgang/identifo/jwt/service"
)

var adminPanelFSSettings = model.FileStorageSettings{
Type: model.FileStorageTypeLocal,
Local: model.FileStorageLocal{
FolderPath: "./static/admin_panel",
},
}

var defaultLoginWebAppFSSettings = model.FileStorageSettings{
Type: model.FileStorageTypeLocal,
Local: model.FileStorageLocal{
FolderPath: "./static/web",
},
}

var defaultEmailTemplateFSSettings = model.FileStorageSettings{
Type: model.FileStorageTypeLocal,
Local: model.FileStorageLocal{
FolderPath: "./static/email_templates",
},
}

// NewServer creates new server instance from ServerSettings
func NewServer(config model.ConfigurationStorage, restartChan chan<- bool) (model.Server, error) {
// read settings, if they empty or use cached version
Expand Down Expand Up @@ -54,16 +77,29 @@ func NewServer(config model.ConfigurationStorage, restartChan chan<- bool) (mode
return nil, err
}

static, err := storage.NewStaticFileStorage(settings.Static)
key, err := storage.NewKeyStorage(settings.KeyStorage)
if err != nil {
return nil, err
}

key, err := storage.NewKeyStorage(settings.KeyStorage)
lwas := settings.LoginWebApp
if settings.LoginWebApp.Type == model.FileStorageTypeNone {
// if not set, use default value
lwas = defaultLoginWebAppFSSettings
}
loginFS, err := storage.NewFS(lwas)
if err != nil {
return nil, err
}

var adminPanelFS fs.FS
if settings.AdminPanel.Enabled == true {
adminPanelFS, err = storage.NewFS(adminPanelFSSettings)
if err != nil {
return nil, err
}
}

sc := model.ServerStorageCollection{
App: app,
User: user,
Expand All @@ -73,8 +109,9 @@ func NewServer(config model.ConfigurationStorage, restartChan chan<- bool) (mode
Verification: verification,
Session: session,
Config: config,
Static: static,
Key: key,
LoginAppFS: loginFS,
AdminPanelFS: adminPanelFS,
}

// create 3rd party services
Expand All @@ -83,7 +120,16 @@ func NewServer(config model.ConfigurationStorage, restartChan chan<- bool) (mode
return nil, err
}

email, err := mail.NewService(settings.Services.Email, static)
ets := settings.EmailTemplates
if ets.Type == model.FileStorageTypeNone {
ets = defaultEmailTemplateFSSettings
}
emailTemplateFS, err := storage.NewFS(ets)
if err != nil {
return nil, err
}

email, err := mail.NewService(settings.Services.Email, emailTemplateFS)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions config/storage/file/file_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ func (cs *ConfigurationStorage) LoadServerSettings(forceReload bool) (model.Serv
settings.Config = cs.config
cs.cache = settings
cs.cached = true

return settings, settings.Validate()
return settings, settings.Validate(true)
}

// GetUpdateChan returns update channel.
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/gorilla/mux v1.7.3
github.com/gorilla/schema v1.2.0 // indirect
github.com/gorilla/sessions v1.2.1
github.com/jszwec/s3fs v0.3.1 // indirect
github.com/klauspost/compress v1.13.4 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/mailgun/mailgun-go v1.1.1
Expand All @@ -31,6 +32,7 @@ require (
github.com/sfreiberg/gotwilio v0.0.0-20201211181435-c426a3710ab5
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/spf13/afero v1.6.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/urfave/negroni v1.0.0
github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/MadAppGang/gotwilio v0.0.0-20210820024906-f91dd2ebe762 h1:QR4fcazNB26XMR4yP8iV/JT0gTCTpZWNKbSVSZPzfM0=
github.com/MadAppGang/gotwilio v0.0.0-20210820024906-f91dd2ebe762/go.mod h1:TftQno2s/uKwhrFst15TKuh272J5QtpW2Nbh1RmtpUY=
github.com/aws/aws-sdk-go v1.36.24/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go v1.38.45 h1:pQmv1vT/voRAjENnPsT4WobFBgLwnODDFogrt2kXc7M=
github.com/aws/aws-sdk-go v1.38.45/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/casbin/casbin v1.9.1 h1:ucjbS5zTrmSLtH4XogqOG920Poe6QatdXtz1FEbApeM=
Expand Down Expand Up @@ -192,6 +193,8 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jszwec/s3fs v0.3.1 h1:ITI7cCnb7yWe2ytoNSz4eJ7HFvCqSsLKylByRh7f6KQ=
github.com/jszwec/s3fs v0.3.1/go.mod h1:+FmWmocDLzba/O3eTTc2MXb1a3O8vkoul2C/Cm2lNOc=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand All @@ -202,6 +205,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down Expand Up @@ -242,6 +246,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand All @@ -261,6 +266,8 @@ github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down Expand Up @@ -305,6 +312,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down
Loading

0 comments on commit 24ca815

Please sign in to comment.