-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OAuthWeb Credential Flow Should Run a Local Server (#20)
The OAuthWebCredentialFlow should run a local server that the OAuth web flow can redirect to to automatically pass the OAuth token. This code is based a lot on the OIDCWebFlow.
- Loading branch information
Showing
4 changed files
with
241 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package gcp | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"go.uber.org/zap" | ||
"google.golang.org/api/gmail/v1" | ||
) | ||
|
||
func Test_WebFlowHelepr(t *testing.T) { | ||
if os.Getenv("GITHUB_ACTIONS") != "" { | ||
t.Skip("Skipping test in GitHub Actions") | ||
} | ||
dLog, err := zap.NewDevelopmentConfig().Build() | ||
if err != nil { | ||
t.Fatalf("Error creating logger: %v", err) | ||
} | ||
zap.ReplaceGlobals(dLog) | ||
|
||
clientSecret := "/Users/jlewi/secrets/gctl.oauthclientid.foyle-dev.json" | ||
flow, err := NewWebFlowHelper(clientSecret, []string{gmail.GmailReadonlyScope}) | ||
if err != nil { | ||
t.Fatalf("Error creating web flow helper: %v", err) | ||
} | ||
|
||
ts, err := flow.Run() | ||
if err != nil { | ||
t.Fatalf("Error getting token source: %v", err) | ||
} | ||
|
||
if _, err := ts.Token(); err != nil { | ||
t.Fatalf("Error getting token: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters