Skip to content

Commit efc9c6c

Browse files
committed
Removed oauth logic
1 parent 0911c2c commit efc9c6c

36 files changed

+273
-2662
lines changed

README.md

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* [Start in docker](#start-in-docker)
1515
- [Getting started](#getting-started)
1616
* [Jaeger](#jaeger)
17-
* [Oauth2 client](#oauth2-client)
1817
* [Http with gRPC](#http-example-with-grpc)
1918
* [Graphql with gRPC](#graphql-example-with-grpc)
2019
- [Deprecate version](#deprecated-version)
@@ -27,9 +26,8 @@ Commands list:
2726
1. Daemon - main service
2827
2. Product service - service that returns Product, an example of gRPC client/server interaction
2928
3. Health check service - this service is needed to show how convenient to understand on which of the services an error occurred in jaeger
30-
4. Oauth client - this service is needed to show a simple example of http client and server, for example oauth2 server
31-
5. Migrate - commands for migration
32-
6. JWT - commands for generate JWT token
29+
4. Migrate - commands for migration
30+
5. JWT - commands for generate JWT token
3331

3432
# Package list
3533

@@ -43,15 +41,14 @@ Packages which use in this example project
4341
6. [gorm](https://github.com/jinzhu/gorm) - database ORM
4442
7. [zap](https://github.com/uber-go/zap) - logger
4543
8. [mux](https://github.com/gorilla/mux) - http router
46-
9. [oauth2](https://github.com/go-oauth2/oauth2) - simple oauth2 server
44+
9. [nats-streaming](https://github.com/nats-io/stan.go) - NATS Streaming System
4745
10. [gqlgen](https://github.com/99designs/gqlgen) - graphql server library
4846
11. [protobuf](https://github.com/golang/protobuf) - Google's data interchange format
4947
12. [grpc](google.golang.org/grpc) - RPC framework
5048
13. [jaeger](https://github.com/uber/jaeger-client-go) - Jaeger Bindings for Go OpenTracing API
5149
14. [casbin](https://github.com/casbin/casbin) - Supports access control
5250
15. [dataloaden](https://github.com/vektah/dataloaden) - DataLoader for graphql
5351
16. [nats](https://github.com/nats-io/nats.go) - Golang client for NATS, the cloud native messaging system
54-
17. [nats-streaming](https://github.com/nats-io/stan.go) - NATS Streaming System
5552

5653
# Installing
5754

@@ -142,12 +139,6 @@ or
142139
./artifacts/bin daemon -c ./artifacts/configs/development.yaml -d
143140
```
144141

145-
Start client
146-
147-
```$xslt
148-
./artifacts/bin oauth-client -c ./artifacts/configs/development.yaml -d
149-
```
150-
151142
Start product service
152143

153144
```$xslt
@@ -177,12 +168,6 @@ docker-compose up
177168
http://localhost:16686
178169
```
179170

180-
## Oauth2 client
181-
182-
```$xslt
183-
http://localhost:9094/login
184-
```
185-
186171
## Http example with gRPC
187172

188173
```$xslt
@@ -265,6 +250,7 @@ mutation createUser {
265250

266251
# Testing
267252
```
268-
export APP_WD=go_path to project_path/resources or project_path/artifacts - needed for load templates
253+
Set APP_WD for load templates as example if you use html pages in a project
254+
export APP_WD=go_path to project_path/resources or project_path/artifacts
269255
➜ make test
270256
```

app/auth/middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type keys struct {
5050
}
5151

5252
// Handler for check Bearer token
53-
func (m Middleware) Handler(next http.Handler) http.Handler {
53+
func (m Middleware) JWTHandler(next http.Handler) http.Handler {
5454
fn := func(w http.ResponseWriter, r *http.Request) {
5555
var (
5656
token string

app/http/http.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ func (m *Http) ListenAndServe(wg *sync.WaitGroup, bind ...string) (server *http.
6060
}
6161

6262
// New
63-
func New(ctx context.Context, mux *chi.Mux, log logger.Logger, cfg Config, managers Managers) *Http {
63+
func New(ctx context.Context, mux *chi.Mux, log logger.Logger, cfg Config) *Http {
6464
return &Http{
65-
ctx: ctx,
66-
cfg: cfg,
67-
session: managers.session,
68-
mux: mux,
69-
log: log.WithFields(logger.Fields{"service": prefix}),
65+
ctx: ctx,
66+
cfg: cfg,
67+
mux: mux,
68+
log: log.WithFields(logger.Fields{"service": prefix}),
7069
}
7170
}

app/http/injector.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ import (
77
"github.com/aristat/golang-example-app/app/db"
88
"github.com/aristat/golang-example-app/app/db/repo"
99
"github.com/aristat/golang-example-app/app/graphql"
10-
oauth_router "github.com/aristat/golang-example-app/app/http_routers/oauth-router"
1110
products_router "github.com/aristat/golang-example-app/app/http_routers/products-router"
12-
users_router "github.com/aristat/golang-example-app/app/http_routers/users-router"
1311
"github.com/aristat/golang-example-app/app/provider"
14-
"github.com/aristat/golang-example-app/app/session"
1512
"github.com/google/wire"
1613
)
1714

@@ -21,10 +18,7 @@ func Build() (*Http, func(), error) {
2118
ProviderProductionSet,
2219
auth.ProviderProductionSet,
2320
graphql.ProviderProductionSet,
24-
users_router.ProviderProductionSet,
2521
products_router.ProviderProductionSet,
26-
oauth_router.ProviderProductionSet,
27-
session.ProviderProductionSet,
2822
repo.ProviderProductionSet,
2923
db.ProviderProductionSet,
3024
provider.AwareProductionSet,

app/http/provider.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@ import (
1010
"github.com/aristat/golang-example-app/app/auth"
1111

1212
"github.com/aristat/golang-example-app/app/graphql"
13-
users_router "github.com/aristat/golang-example-app/app/http_routers/users-router"
1413
"github.com/go-chi/chi"
1514
"github.com/go-chi/chi/middleware"
1615
"github.com/opentracing/opentracing-go"
1716

18-
"github.com/go-session/session"
19-
2017
"github.com/aristat/golang-example-app/app/logger"
2118

22-
oauth_router "github.com/aristat/golang-example-app/app/http_routers/oauth-router"
2319
"github.com/google/wire"
2420
"github.com/spf13/viper"
2521
)
@@ -54,19 +50,14 @@ func Mux(managers Managers, log logger.Logger, tracer opentracing.Tracer) (*chi.
5450
mux.Use(Tracer(tracer))
5551
mux.Use(dataloader.LoaderMiddleware)
5652

57-
managers.users.Router.Run(mux)
58-
managers.oauth.Router.Run(mux)
5953
managers.products.Router.Run(mux)
60-
managers.graphql.Routers(mux.With(managers.authMiddleware.Handler))
54+
managers.graphql.Routers(mux.With(managers.authMiddleware.JWTHandler))
6155

6256
return mux, func() {}, nil
6357
}
6458

6559
// ServiceManagers
6660
type Managers struct {
67-
session *session.Manager
68-
users *users_router.Manager
69-
oauth *oauth_router.Manager
7061
products *products_router.Manager
7162
authMiddleware *auth.Middleware
7263
graphql *graphql.GraphQL
@@ -77,8 +68,8 @@ var ProviderManagers = wire.NewSet(
7768
)
7869

7970
// Provider
80-
func Provider(ctx context.Context, mux *chi.Mux, log logger.Logger, cfg Config, managers Managers) (*Http, func(), error) {
81-
g := New(ctx, mux, log, cfg, managers)
71+
func Provider(ctx context.Context, mux *chi.Mux, log logger.Logger, cfg Config) (*Http, func(), error) {
72+
g := New(ctx, mux, log, cfg)
8273
return g, func() {}, nil
8374
}
8475

0 commit comments

Comments
 (0)