fix: example client should track state, call cli.CodeFlow need context

This commit is contained in:
wener 2021-10-08 00:15:38 +08:00
parent a63fbee93d
commit 0de2cc1d24
2 changed files with 5 additions and 4 deletions

View file

@ -43,7 +43,7 @@ func main() {
state := func() string { state := func() string {
return uuid.New().String() return uuid.New().String()
} }
token := cli.CodeFlow(relyingParty, callbackPath, port, state) token := cli.CodeFlow(ctx, relyingParty, callbackPath, port, state)
client := github.NewClient(relyingParty.OAuthConfig().Client(ctx, token.Token)) client := github.NewClient(relyingParty.OAuthConfig().Client(ctx, token.Token))

View file

@ -36,6 +36,7 @@ type AuthRequest struct {
Nonce string Nonce string
ClientID string ClientID string
CodeChallenge *oidc.CodeChallenge CodeChallenge *oidc.CodeChallenge
State string
} }
func (a *AuthRequest) GetACR() string { func (a *AuthRequest) GetACR() string {
@ -98,7 +99,7 @@ func (a *AuthRequest) GetScopes() []string {
func (a *AuthRequest) SetCurrentScopes(scopes []string) {} func (a *AuthRequest) SetCurrentScopes(scopes []string) {}
func (a *AuthRequest) GetState() string { func (a *AuthRequest) GetState() string {
return "" return a.State
} }
func (a *AuthRequest) GetSubject() string { func (a *AuthRequest) GetSubject() string {
@ -120,7 +121,7 @@ func (s *AuthStorage) Health(ctx context.Context) error {
} }
func (s *AuthStorage) CreateAuthRequest(_ context.Context, authReq *oidc.AuthRequest, _ string) (op.AuthRequest, error) { func (s *AuthStorage) CreateAuthRequest(_ context.Context, authReq *oidc.AuthRequest, _ string) (op.AuthRequest, error) {
a = &AuthRequest{ID: "id", ClientID: authReq.ClientID, ResponseType: authReq.ResponseType, Nonce: authReq.Nonce, RedirectURI: authReq.RedirectURI} a = &AuthRequest{ID: "id", ClientID: authReq.ClientID, ResponseType: authReq.ResponseType, Nonce: authReq.Nonce, RedirectURI: authReq.RedirectURI, State: authReq.State}
if authReq.CodeChallenge != "" { if authReq.CodeChallenge != "" {
a.CodeChallenge = &oidc.CodeChallenge{ a.CodeChallenge = &oidc.CodeChallenge{
Challenge: authReq.CodeChallenge, Challenge: authReq.CodeChallenge,
@ -212,7 +213,7 @@ func (s *AuthStorage) GetClientByClientID(_ context.Context, id string) (op.Clie
accessTokenType = op.AccessTokenTypeJWT accessTokenType = op.AccessTokenTypeJWT
responseTypes = []oidc.ResponseType{oidc.ResponseTypeIDToken, oidc.ResponseTypeIDTokenOnly} responseTypes = []oidc.ResponseType{oidc.ResponseTypeIDToken, oidc.ResponseTypeIDTokenOnly}
} }
return &ConfClient{ID: id, applicationType: appType, authMethod: authMethod, accessTokenType: accessTokenType, responseTypes: responseTypes, devMode: false}, nil return &ConfClient{ID: id, applicationType: appType, authMethod: authMethod, accessTokenType: accessTokenType, responseTypes: responseTypes, devMode: false, grantTypes: []oidc.GrantType{oidc.GrantTypeCode}}, nil
} }
func (s *AuthStorage) AuthorizeClientIDSecret(_ context.Context, id string, _ string) error { func (s *AuthStorage) AuthorizeClientIDSecret(_ context.Context, id string, _ string) error {