Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit a9035d4

Browse files
committed
Impl StartOauthLogin
1 parent 514f384 commit a9035d4

File tree

6 files changed

+136
-40
lines changed

6 files changed

+136
-40
lines changed

.env.sample

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# for ridgepole
22
DATABASE_URL=mysql2://root:[email protected]:3306/accounts?parseTime=true
3+
ACCOUNTS_DB_PASSWORD=password
4+
5+
# for hydra
6+
DATABASE_URL_HYDRA=mysql://root:password@tcp(mysql:3306)/hydra?parseTime=true
7+
HYDRA_SECRET=youReallyNeedToChangeThis
8+
HYDRA_SALT=youReallyNeedToChangeThis
9+
OAUTH2_ISSUER_URL=http://localhost:4444
10+
OAUTH2_CONSENT_URL=http://localhost:3000/oauth/consent
11+
OAUTH2_LOGIN_URL=http://localhost:3000/oauth/login
312

413
DATA_SOURCE_NAME=root:password@tcp(mysql:3306)/accounts?parseTime=true
14+
515
REDIS_ADDR=redis:6379
16+
617
DEBUG_LOG=true
18+
19+
HYDRA_ADMIN_URL=http://localhost:4445

api/oauth.pb.go

Lines changed: 45 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/oauth.swagger.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
"prolab_accountsStartOAuthLoginResponse": {
7272
"type": "object",
7373
"properties": {
74+
"skip": {
75+
"type": "boolean",
76+
"format": "boolean"
77+
},
7478
"redirect_url": {
7579
"type": "string"
7680
}

api/protos/oauth.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ service OAuthService {
2222
}
2323

2424
message StartOauthLoginRequest {
25-
string challenge = 1;
25+
string login_challenge = 1;
2626
}
2727

2828
message StartOAuthLoginResponse {
29-
string redirect_url = 1;
29+
bool skip = 1;
30+
string redirect_url = 2;
3031
}
3132

3233
message OAuthLoginRequest {

app/server/oauth_server.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"context"
55

66
"github.com/izumin5210/grapi/pkg/grapiserver"
7+
"github.com/ory/hydra/sdk/go/hydra/swagger"
78
"google.golang.org/grpc/codes"
9+
"google.golang.org/grpc/grpclog"
810
"google.golang.org/grpc/status"
911

1012
api_pb "github.com/ProgrammingLab/prolab-accounts/api"
@@ -29,8 +31,31 @@ type oAuthServiceServerImpl struct {
2931
}
3032

3133
func (s *oAuthServiceServerImpl) StartOauthLogin(ctx context.Context, req *api_pb.StartOauthLoginRequest) (*api_pb.StartOAuthLoginResponse, error) {
32-
// TODO: Not yet implemented.
33-
return nil, status.Error(codes.Unimplemented, "TODO: You should implement it!")
34+
cli := s.HydraClient(ctx)
35+
challenge := req.GetLoginChallenge()
36+
res, _, err := cli.GetLoginRequest(challenge)
37+
if err != nil {
38+
grpclog.Error(err)
39+
return nil, err
40+
}
41+
if res.Skip {
42+
res, _, err := cli.AcceptLoginRequest(challenge, swagger.AcceptLoginRequest{})
43+
if err != nil {
44+
grpclog.Error(err)
45+
return nil, err
46+
}
47+
48+
resp := &api_pb.StartOAuthLoginResponse{
49+
Skip: true,
50+
RedirectUrl: res.RedirectTo,
51+
}
52+
return resp, nil
53+
}
54+
55+
resp := &api_pb.StartOAuthLoginResponse{
56+
Skip: false,
57+
}
58+
return resp, nil
3459
}
3560

3661
func (s *oAuthServiceServerImpl) OAuthLogin(ctx context.Context, req *api_pb.OAuthLoginRequest) (*api_pb.OAuthLoginResponse, error) {

docker-compose.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,53 @@ services:
1111
depends_on:
1212
- mysql
1313
- redis
14+
- hydra
1415
ports:
1516
- "3000:3000"
1617

18+
hydra-migrate:
19+
image: oryd/hydra:v1.0.0-rc.6_oryOS.10-alpine
20+
depends_on:
21+
- mysql
22+
environment:
23+
# - LOG_LEVEL=debug
24+
- DATABASE_URL=${DATABASE_URL_HYDRA}
25+
command:
26+
migrate sql -e
27+
restart: on-failure
28+
29+
hydra:
30+
image: oryd/hydra:v1.0.0-rc.6_oryOS.10-alpine
31+
depends_on:
32+
- hydra-migrate
33+
ports:
34+
# Public port
35+
- "4444:4444"
36+
# Admin port
37+
- "4445:4445"
38+
# Port for hydra token user
39+
- "5555:5555"
40+
command:
41+
serve all --dangerous-force-http
42+
environment:
43+
# - LOG_LEVEL=debug
44+
- OAUTH2_ISSUER_URL=${OAUTH2_ISSUER_URL}
45+
- OAUTH2_CONSENT_URL=${OAUTH2_CONSENT_URL}
46+
- OAUTH2_LOGIN_URL=${OAUTH2_LOGIN_URL}
47+
- DATABASE_URL=${DATABASE_URL_HYDRA}
48+
- SYSTEM_SECRET=${HYDRA_SECRET}
49+
- OAUTH2_SHARE_ERROR_DEBUG=1
50+
- OIDC_SUBJECT_TYPES_SUPPORTED=public,pairwise
51+
- OIDC_SUBJECT_TYPE_PAIRWISE_SALT=${HYDRA_SALT}
52+
# - OAUTH2_ACCESS_TOKEN_STRATEGY=jwt
53+
# Uncomment the following lines when configuring tracing
54+
# - TRACING_PROVIDER=jaeger
55+
# - TRACING_PROVIDER_JAEGER_SAMPLING_SERVER_URL=http://jaeger:5778/sampling
56+
# - TRACING_PROVIDER_JAEGER_LOCAL_AGENT_ADDRESS=jaeger:6831
57+
# - TRACING_PROVIDER_JAEGER_SAMPLING_TYPE=const
58+
# - TRACING_PROVIDER_JAEGER_SAMPLING_VALUE=1
59+
restart: unless-stopped
60+
1761
mysql:
1862
image: mysql:5.7
1963
hostname: mysql

0 commit comments

Comments
 (0)