All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.aws.smithy.kotlin.runtime.http.auth.BearerTokenSigner.kt Maven / Gradle / Ivy

There is a newer version: 1.3.25
Show newest version
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

package aws.smithy.kotlin.runtime.http.auth

import aws.smithy.kotlin.runtime.net.isSecure

/**
 * [HttpSigner] that signs outgoing requests using the provided [BearerToken] identity
 */
public class BearerTokenSigner : HttpSigner {
    override suspend fun sign(signingRequest: SignHttpRequest) {
        val identity = signingRequest.identity
        check(identity is BearerToken) { "expected a ${BearerToken::class} identity; found ${signingRequest.identity::class}" }

        // RFC 6750 § 5.2
        check(signingRequest.httpRequest.url.scheme.isSecure) { "https is required to use Bearer token auth" }

        val credentials = "Bearer ${identity.token}"
        signingRequest.httpRequest.headers["Authorization"] = credentials
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy