Skip to content

Commit

Permalink
Resolve conflicts and remove kratos auth
Browse files Browse the repository at this point in the history
  • Loading branch information
dzungtran committed Dec 19, 2023
2 parents f012cf6 + 1efc9dc commit 94ea737
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 239 deletions.
3 changes: 0 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@ AUTH_PROVIDER=firebase
FIREBASE_CREDENTIALS='{firebase json admin key}'
FIREBASE_AUTH_CREDENTIALS='{filebase json auth key}'

# KRATOS_API_ENDPOINT=http://kratos:4433/
# KRATOS_WEBHOOK_API_KEY=very-very-very-secure-api-key

AUTO_MIGRATE=true
PORT=8088
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ Any feedback and pull requests are welcome and highly appreciated. Feel free to
<!--toc-->
- [Echo REST API boilerplate](#echo-rest-api-boilerplate)
- [HOW TO USE THIS TEMPLATE](#how-to-use-this-template)
- [Overview](#overview)
- [Features](#features)
- [Running the project](#running-the-project)
- [Swagger Docs](#swagger-docs)
- [Environment variables](#environment-variables)
- [Commands](#commands)
- [Folder structure](#folder-structure)
- [Open source refs](#open-source-refs)
- [Folder Structure](#folder-structure)
- [Open Source Refs](#open-source-refs)
- [Contributing](#contributing)
- [TODOs](#todos)

Expand All @@ -39,8 +41,6 @@ Any feedback and pull requests are welcome and highly appreciated. Feel free to
<!--
## Overview
![Request processing flow - Sequence Diagram](out/docs/diagrams/overview/request_flow.svg) -->
## Features
Expand Down Expand Up @@ -86,8 +86,6 @@ Setting your config as Environment Variables is recommended as by 12-Factor App.
| AUTH_PROVIDER | string | Optional | firebase_auth |
| FIREBASE_CREDENTIALS | json | firebase json admin key | {firebase_admin_key} |
| FIREBASE_AUTH_CREDENTIALS | json | filebase json auth key | {firebase_auth_key} |
| KRATOS_API_ENDPOINT | string | [DEPRECATED] Public endpoint of Kratos | http://kratos:4433/ |
| KRATOS_WEBHOOK_API_KEY | string | [DEPRECATED] Api key for Kratos integration | very-very-very-secure-api-key |
</details>
## Commands
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ require (
github.com/lib/pq v1.10.6
github.com/lithammer/shortuuid/v4 v4.0.0
github.com/open-policy-agent/opa v0.54.0
github.com/ory/kratos-client-go v0.11.1
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.2
github.com/swaggo/echo-swagger v1.4.0
github.com/swaggo/swag v1.16.1
github.com/tidwall/gjson v1.15.0
github.com/tidwall/sjson v1.2.5
go.uber.org/dig v1.17.0
go.uber.org/zap v1.24.0
Expand Down Expand Up @@ -104,6 +102,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
github.com/tidwall/gjson v1.17.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
Expand All @@ -119,7 +118,7 @@ require (
go.uber.org/goleak v1.2.1 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.15.0 // indirect
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,6 @@ github.com/opencontainers/selinux v1.8.0/go.mod h1:RScLhm78qiWa2gbVCcGkC7tCGdgk3
github.com/opencontainers/selinux v1.8.2/go.mod h1:MUIHuUEvKB1wtJjQdOyYRgOnLD2xAPP8dBsCoU0KuF8=
github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/ory/kratos-client-go v0.11.1 h1:2f+WZ94NReAUQlxdV/pp1ipScy5o5gYLHt2ThSNHHeA=
github.com/ory/kratos-client-go v0.11.1/go.mod h1:G31LzGZxgtMblK36qaTPWjG5OqnUWrncO1MjKkHsFUE=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
Expand Down Expand Up @@ -1241,8 +1239,8 @@ github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ
github.com/tchap/go-patricia/v2 v2.3.1 h1:6rQp39lgIYZ+MHmdEq4xzuk1t7OdC35z/xm0BGhTkes=
github.com/tchap/go-patricia/v2 v2.3.1/go.mod h1:VZRHKAb53DLaG+nA9EaYYiaEx6YztwDlLElMsnSHD4k=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.15.0 h1:5n/pM+v3r5ujuNl4YLZLsQ+UE5jlkLVm7jMzT5Mpolw=
github.com/tidwall/gjson v1.15.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM=
github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
Expand Down Expand Up @@ -1537,8 +1535,8 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/net v0.0.0-20220708220712-1185a9018129/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.0.0-20180227000427-d7d64896b5ff/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down
118 changes: 0 additions & 118 deletions modules/core/handlers/kratos.go

This file was deleted.

1 change: 0 additions & 1 deletion modules/core/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func (coreModule) RegisterHandlers(g *echo.Group, container *dig.Container) erro
) {
handlers.NewOrgHandler(g, middManager, orgUsecase)
handlers.NewUserHandler(g, middManager, userUsecase)
handlers.NewKratosHookHandler(g, middManager, userUsecase)
handlers.NewAuthHandler(g, middManager, userUsecase, appConf)
})
}
17 changes: 0 additions & 17 deletions pkg/kratos/client.go

This file was deleted.

73 changes: 0 additions & 73 deletions pkg/middlewares/kratos.go

This file was deleted.

18 changes: 6 additions & 12 deletions pkg/middlewares/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
"github.com/dzungtran/echo-rest-api/pkg/authz"
"github.com/dzungtran/echo-rest-api/pkg/constants"
"github.com/dzungtran/echo-rest-api/pkg/contexts"
"github.com/dzungtran/echo-rest-api/pkg/kratos"
"github.com/dzungtran/echo-rest-api/pkg/utils"
"github.com/labstack/echo/v4"
ory "github.com/ory/kratos-client-go"
)

// MiddlewareManager ...
Expand All @@ -29,8 +27,7 @@ type MiddlewareManager struct {
orgRepo coreRepo.OrgRepository
projectRepo projectRepo.ProjectRepository

userUC usecases.UserUsecase
kratosClient *ory.APIClient
userUC usecases.UserUsecase
}

// NewMiddlewareManager will create new an MiddlewareManager object
Expand All @@ -45,21 +42,18 @@ func NewMiddlewareManager(
userUC usecases.UserUsecase,
) *MiddlewareManager {
return &MiddlewareManager{
appConf: appConf,
userRepo: userRepo,
userOrgRepo: userOrgRepo,
orgRepo: orgRepo,
userUC: userUC,
kratosClient: kratos.NewKratosSelfHostedClient(appConf.KratosApiEndpoint, appConf.Environment == "development"),
appConf: appConf,
userRepo: userRepo,
userOrgRepo: userOrgRepo,
orgRepo: orgRepo,
userUC: userUC,
}
}

func (m MiddlewareManager) Auth() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {

switch m.appConf.AuthProvider {
case "kratos":
return m.KratosAuth(next)
default:
// Default auth method
return m.FireBaseAuth(next)
Expand Down

0 comments on commit 94ea737

Please sign in to comment.