Skip to content

Instantly share code, notes, and snippets.

Created December 14, 2022 03:37
What would you like to do?
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:
Then enter the code:
`, 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