Skip to content

Commit

Permalink
fix authenticated client & dev config
Browse files Browse the repository at this point in the history
  • Loading branch information
patrislav committed Jun 6, 2024
1 parent f12d5eb commit b097471
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 11 additions & 0 deletions etc/waas-auth.dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ QwIDAQAB
tenants_table = "dev_tenants"
accounts_table = "dev_accounts"
sessions_table = "dev_sessions"
verification_contexts_table = "dev_verification_contexts"

[kms]
tenant_keys = ["arn:aws:kms:ca-central-1:767397863481:key/eea4d73b-f055-4941-9fc9-8ed3cff162be"]
default_session_keys = ["arn:aws:kms:ca-central-1:767397863481:key/eea4d73b-f055-4941-9fc9-8ed3cff162be"]

[ses]
region = "ca-central-1"
source = "[email protected]"
source_arn = "arn:aws:ses:ca-central-1:471112647196:identity/sequence.app"
access_role_arn = "arn:aws:iam::471112647196:role/dev-mailer-c797a23"

[builder]
base_url = "https://dev-api.sequence.build"
secret_id = "dev-builder-jwt"
14 changes: 3 additions & 11 deletions proto/builder/authenticated_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,17 @@ func NewAuthenticatedClient(httpClient HTTPClient, sm *secretsmanager.Client, se
}

func (c *AuthenticatedClient) Do(req *http.Request) (*http.Response, error) {
ctx := req.Context()

token, exp := c.getToken()
if token == "" || time.Now().After(exp) {
var err error
token, err = c.fetchToken(ctx)
token, err = c.fetchToken(req.Context())
if err != nil {
return nil, err
}
}

h := http.Header{}
h.Set("Authorization", fmt.Sprintf("Bearer %s", token))
ctx, err := WithHTTPRequestHeaders(ctx, h)
if err != nil {
return nil, err
}

return c.Do(req.WithContext(ctx))
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
return c.HTTPClient.Do(req)
}

func (c *AuthenticatedClient) getToken() (string, time.Time) {
Expand Down

0 comments on commit b097471

Please sign in to comment.