OAuth Device Flow part one
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
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