@@ -11,9 +11,12 @@ import (
11
11
"github.com/ory/hydra/sdk/go/hydra/swagger"
12
12
"github.com/pkg/errors"
13
13
"golang.org/x/crypto/bcrypt"
14
+ "google.golang.org/grpc/codes"
14
15
"google.golang.org/grpc/grpclog"
16
+ "google.golang.org/grpc/status"
15
17
16
18
api_pb "github.com/ProgrammingLab/prolab-accounts/api"
19
+ type_pb "github.com/ProgrammingLab/prolab-accounts/api/type"
17
20
"github.com/ProgrammingLab/prolab-accounts/app/di"
18
21
"github.com/ProgrammingLab/prolab-accounts/app/util"
19
22
)
@@ -82,7 +85,7 @@ func (s *oAuthServiceServerImpl) OAuthLogin(ctx context.Context, req *api_pb.OAu
82
85
Remember : req .Remember ,
83
86
RememberFor : int64 (time .Hour .Seconds ()),
84
87
}
85
- res , _ , err := cli .AcceptLoginRequest (req .GetChallenge (), acReq )
88
+ res , _ , err := cli .AcceptLoginRequest (req .GetLoginChallenge (), acReq )
86
89
if err != nil {
87
90
log .Error (err )
88
91
return nil , err
@@ -94,3 +97,53 @@ func (s *oAuthServiceServerImpl) OAuthLogin(ctx context.Context, req *api_pb.OAu
94
97
95
98
return resp , nil
96
99
}
100
+
101
+ func (s * oAuthServiceServerImpl ) StartOauthConsent (ctx context.Context , req * api_pb.StartOauthConsentRequest ) (* api_pb.StartOauthConsentResponse , error ) {
102
+ cli := s .HydraClient (ctx )
103
+ challenge := req .GetConsentChallenge ()
104
+ res , _ , err := cli .GetConsentRequest (challenge )
105
+ if err != nil {
106
+ log .Error (err )
107
+ return nil , err
108
+ }
109
+ if res .Skip {
110
+ req := swagger.AcceptConsentRequest {
111
+ GrantScope : res .RequestedScope ,
112
+ GrantAccessTokenAudience : res .RequestedAccessTokenAudience ,
113
+ }
114
+ res , _ , err := cli .AcceptConsentRequest (challenge , req )
115
+ if err != nil {
116
+ log .Error (err )
117
+ return nil , err
118
+ }
119
+
120
+ resp := & api_pb.StartOauthConsentResponse {
121
+ Skip : true ,
122
+ RedirectUrl : res .RedirectTo ,
123
+ }
124
+ return resp , nil
125
+ }
126
+
127
+ resp := & api_pb.StartOauthConsentResponse {
128
+ Skip : false ,
129
+ RequestedScopes : res .RequestedScope ,
130
+ Client : clientToResponse (res .Client ),
131
+ }
132
+ return resp , nil
133
+ }
134
+
135
+ func (s * oAuthServiceServerImpl ) OAuthConsent (context.Context , * api_pb.OAuthConsentRequest ) (* api_pb.OAuthConsentResponse , error ) {
136
+ // TODO: Not yet implemented.
137
+ return nil , status .Error (codes .Unimplemented , "TODO: You should implement it!" )
138
+ }
139
+
140
+ func clientToResponse (cli swagger.OAuth2Client ) * type_pb.Client {
141
+ return & type_pb.Client {
142
+ Id : cli .ClientId ,
143
+ Name : cli .ClientName ,
144
+ Uri : cli .ClientUri ,
145
+ Contacts : cli .Contacts ,
146
+ LogoUri : cli .LogoUri ,
147
+ Owner : cli .Owner ,
148
+ }
149
+ }
0 commit comments