Skip to content

Commit

Permalink
Added error checks and access token var
Browse files Browse the repository at this point in the history
  • Loading branch information
davidallendj committed Feb 28, 2024
1 parent 4a14783 commit 0265295
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cmd/boot-script-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -96,6 +97,7 @@ var (
useSQL = false // Use ETCD by default
authRetryCount = authDefaultRetryCount
jwksURL = ""
accessToken = ""
sqlDbOpts = ""
spireServiceURL = "https://spire-tokens.spire:54440"
)
Expand Down Expand Up @@ -445,8 +447,19 @@ func main() {

// register oauth client and receive
var client OAuthClient
client.RegisterOAuthClient("http://127.0.0.1:4444/oauth2/register", []string{})
client.FetchTokenFromAuthorizationServer("http://127.0.0.1:4444/oauth2/token", []string{})
_, err = client.RegisterOAuthClient("http://127.0.0.1:4444/oauth2/register", []string{})
if err != nil {
log.Fatalf("failed to register OAuth client: %v", err)
}
res, err := client.FetchTokenFromAuthorizationServer("http://127.0.0.1:4444/oauth2/token", []string{})
if err != nil {
log.Fatalf("failed to fetch token from authorization server: %v", err)
}

// unmarshal the access token
var resJson map[string]any
json.Unmarshal(res, &resJson)
accessToken = resJson["access_token"].(string)

var svcOpts string
if insecure {
Expand Down

0 comments on commit 0265295

Please sign in to comment.