@@ -3,6 +3,7 @@ package main
33import (
44 "context"
55 "flag"
6+ "github.com/grepplabs/kafka-proxy/pkg/apis"
67 "github.com/grepplabs/kafka-proxy/plugin/gateway-client/shared"
78 "github.com/hashicorp/go-plugin"
89 "golang.org/x/oauth2/google"
@@ -18,29 +19,29 @@ type TokenProvider struct {
1819//TODO: caching, expiry
1920//TODO: refresh in the half of time
2021//TODO: send claims
21- func (p TokenProvider ) GetToken (claims [] string ) (int32 , string , error ) {
22+ func (p TokenProvider ) GetToken (request apis. TokenRequest ) (apis. TokenResponse , error ) {
2223
2324 ctx , cancel := context .WithTimeout (context .Background (), time .Duration (p .timeout )* time .Second )
2425 defer cancel ()
2526
2627 tokenSource , err := google .DefaultTokenSource (ctx , oauth2 .UserinfoEmailScope )
2728 if err != nil {
28- return tokenResponse (1 , "" )
29+ return tokenResponse (false , 1 , "" )
2930 }
3031 token , err := tokenSource .Token ()
3132 if err != nil {
32- return tokenResponse (2 , "" )
33+ return tokenResponse (false , 2 , "" )
3334 }
3435 if token .Extra ("id_token" ) == nil {
35- return tokenResponse (3 , "" )
36+ return tokenResponse (false , 3 , "" )
3637 }
3738 idToken := token .Extra ("id_token" ).(string )
38- return tokenResponse (0 , idToken )
39+ return tokenResponse (true , 0 , idToken )
3940
4041}
4142
42- func tokenResponse (status int32 , token string ) (int32 , string , error ) {
43- return status , token , nil
43+ func tokenResponse (success bool , status int32 , token string ) (apis. TokenResponse , error ) {
44+ return apis. TokenResponse { Success : success , Status : status , Token : token } , nil
4445}
4546
4647func (f * TokenProvider ) flagSet () * flag.FlagSet {
0 commit comments