Skip to content

Commit 1da1b87

Browse files
committed
Updating code to remove from python and go
1 parent 4245d0c commit 1da1b87

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/content/docs/r2/examples/authenticate-r2-auth-tokens.mdx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ For providing secure access to bucket objects for anonymous users, we recommend
1313
Pre-signed URLs do not require users to be a member of your organization and enable programmatic application directly.
1414
:::
1515

16-
Ensure you have set the following environmental variables prior to running either example:
16+
Ensure you have set the following environmental variables prior to running either example. Refer to [Get S3 API credentials from an API token](/r2/api/tokens/#get-s3-api-credentials-from-an-api-token) for more information.
1717

1818
```sh
1919
export R2_ACCOUNT_ID=your_account_id
@@ -32,7 +32,6 @@ export R2_BUCKET_NAME=your_bucket_name
3232

3333
```javascript
3434
const AWS = require('aws-sdk');
35-
const crypto = require('crypto');
3635

3736
const ACCOUNT_ID = process.env.R2_ACCOUNT_ID;
3837
const ACCESS_KEY_ID = process.env.R2_ACCESS_KEY_ID;
@@ -99,14 +98,11 @@ export R2_BUCKET_NAME=your_bucket_name
9998
SECRET_ACCESS_KEY = os.environ.get('R2_SECRET_ACCESS_KEY')
10099
BUCKET_NAME = os.environ.get('R2_BUCKET_NAME')
101100

102-
# Hash the secret access key using SHA-256
103-
hashed_secret_key = hashlib.sha256(SECRET_ACCESS_KEY.encode()).hexdigest()
104-
105101
# Configure the S3 client for Cloudflare R2
106102
s3_client = boto3.client('s3',
107103
endpoint_url=f'https://{ACCOUNT_ID}.r2.cloudflarestorage.com',
108104
aws_access_key_id=ACCESS_KEY_ID,
109-
aws_secret_access_key=hashed_secret_key,
105+
aws_secret_access_key=SECRET_ACCESS_KEY,
110106
config=Config(signature_version='s3v4')
111107
)
112108

@@ -149,7 +145,6 @@ export R2_BUCKET_NAME=your_bucket_name
149145

150146
import (
151147
"context"
152-
"crypto/sha256"
153148
"encoding/hex"
154149
"fmt"
155150
"io"
@@ -169,11 +164,6 @@ export R2_BUCKET_NAME=your_bucket_name
169164
secretAccessKey := os.Getenv("R2_SECRET_ACCESS_KEY")
170165
bucketName := os.Getenv("R2_BUCKET_NAME")
171166

172-
// Hash the secret access key
173-
hasher := sha256.New()
174-
hasher.Write([]byte(secretAccessKey))
175-
hashedSecretKey := hex.EncodeToString(hasher.Sum(nil))
176-
177167
// Configure the S3 client for Cloudflare R2
178168
r2Resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
179169
return aws.Endpoint{
@@ -183,7 +173,7 @@ export R2_BUCKET_NAME=your_bucket_name
183173

184174
cfg, err := config.LoadDefaultConfig(context.TODO(),
185175
config.WithEndpointResolverWithOptions(r2Resolver),
186-
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKeyID, hashedSecretKey, "")),
176+
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKeyID, secretAccessKey, "")),
187177
config.WithRegion("auto"), // Cloudflare R2 doesn't use regions, but this is required by the SDK
188178
)
189179
if err != nil {

0 commit comments

Comments
 (0)