babbel / okhttp-aws-signer

AWS V4 signing algorithm for OkHttp requests
MIT License
33 stars 3 forks source link

Getting 403 Forbidden error #12

Open sagarpatel288 opened 3 years ago

sagarpatel288 commented 3 years ago

Using it below way:

https://stackoverflow.com/questions/54568398/the-request-signature-does-not-match-when-access-aws-api-gateway-on-retrofit

We are using the same accessKey and secretKey across platforms such as Android, iOS and Web... Can it be the issue?

s-ka commented 3 years ago

I don't think that this should be a problem. Maybe you can have a look at the code in #11

MaximVod commented 2 years ago

The same problem, I get an error 403, but the fact is that at the moment it works, but not on all phones, and especially on Samsung

I am attaching the code and the error from Crashlytics:

class AwsSignInterceptor(val signer: OkHttpAwsV4Signer) : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request().newBuilder()
                .addHeader("host", getHostHeader())
                .addHeader("x-amz-date", getXAmzDateheader())
                .addHeader("x-amz-content-sha256", "".sha256())
                .addHeader("Range", "")
                .build()
        val signedRequest = signer.sign(request, S3_OBJECT_STORAGE_ACCESS_KEY, S3_OBJECT_STORAGE_SECRET_KEY)
        return chain.proceed(signedRequest)
    }
Non-fatal Exception: retrofit2.HttpException: HTTP 403 Forbidden
       at retrofit2.KotlinExtensions$await$2$2.onResponse(KotlinExtensions.kt:53)
       at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:129)
       at okhttp3.RealCall$AsyncCall.run(RealCall.kt:140)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:919)
s-ka commented 2 years ago

Hey @MaximVod So you say it works not every time. Have you experienced this first hand or do you take this from a crash logger? And is this happening on the initial request? I see that you have set the x-amz-content-sha256 and Range header, which we are not using.