From a549dd29690dc02b196fc8883a34c773470d6b20 Mon Sep 17 00:00:00 2001 From: charlie <742260877@qq.com> Date: Mon, 8 Aug 2022 08:25:54 +0800 Subject: [PATCH] add GetCode --- oauth2cli.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/oauth2cli.go b/oauth2cli.go index 578ecd3..ef1f4a6 100644 --- a/oauth2cli.go +++ b/oauth2cli.go @@ -160,3 +160,16 @@ func GetToken(ctx context.Context, c Config) (*oauth2.Token, error) { } return token, nil } + + +func GetCode(ctx context.Context, c Config) (string, error) { + if err := c.validateAndSetDefaults(); err != nil { + return "", fmt.Errorf("invalid config: %w", err) + } + code, err := receiveCodeViaLocalServer(ctx, &c) + if err != nil { + return "", fmt.Errorf("authorization error: %w", err) + } + + return code, nil +}