Skip to content

Instantly share code, notes, and snippets.

@pmenglund
Created December 14, 2022 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmenglund/5ed2708cdb88b6a6982258aed59a0899 to your computer and use it in GitHub Desktop.
Save pmenglund/5ed2708cdb88b6a6982258aed59a0899 to your computer and use it in GitHub Desktop.
OAuth Device Flow part one
ctx := context.Background()
cfg, err := device.NewConfig("auth0", "rockset", os.Getenv("AUTH0_CLIENT_ID"))
if err != nil {
log.Fatalf("failed to create configuration: %v", err)
}
a := device.NewAuthorizer(cfg)
code, err := a.RequestCode(ctx)
if err != nil {
log.Fatalf("failed to request a device code: %v", err)
}
fmt.Printf(`Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:
%s
Then enter the code:
%s
`, code.VerificationURIComplete, code.UserCode)
token, err := a.WaitForAuthorization(ctx, code)
if err != nil {
log.Fatalf("failed to wait for authorization: %v", err)
}
fmt.Printf("Successfully logged in!\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment