Repository: ktorio/ktor
File: ktor-client/ktor-client-plugins/ktor-client-auth/common/src/io/ktor/client/plugins/auth/providers/BearerAuthProvider.kt (Kotlin)

Code before:
     * [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.client.plugins.auth.BearerAuthConfig.nonCancellableRefresh)
     */
    public var nonCancellableRefresh: Boolean = false
}

/**
 * An authentication provider for the Bearer HTTP authentication scheme.
 * Bearer authentication involves security tokens called bearer tokens.
 * As an example, these tokens can be used as a part of OAuth flow to authorize users of your application
 * by using external providers, such as Google, Facebook, Twitter, and so on.
 *
 * You can learn more from [Bearer authentication](https://ktor.io/docs/bearer-client.html).
 *
 * [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.client.plugins.auth.providers.BearerAuthProvider)
 */
public class BearerAuthProvider(
    private val refreshTokens: suspend RefreshTokensParams.() -> BearerTokens?,
    loadTokens: suspend () -> BearerTokens?,
    private val sendWithoutRequestCallback: (HttpRequestBuilder) -> Boolean = { true },
    private val realm: String?,
    cacheTokens: Boolean = true,
    private val nonCancellableRefresh: Boolean = false,
) : AuthProvider {

    @Deprecated("Maintained for binary compatibility", level = DeprecationLevel.HIDDEN)
    public constructor(
        refreshTokens: suspend (RefreshTokensParams) -> BearerTokens?,
        loadTokens: suspend () -> BearerTokens?,
        sendWithoutRequestCallback: (HttpRequestBuilder) -> Boolean = { true },
        realm: String?,
        cacheTokens: Boolean = true,
    ) : this(refreshTokens, loadTokens, sendWithoutRequestCallback, realm, cacheTokens, nonCancellableRefresh = false)

    public constructor(
        refreshTokens: suspend (RefreshTokensParams) -> BearerTokens?,
        loadTokens: suspend () -> BearerTokens?,
        sendWithoutRequestCallback: (HttpRequestBuilder) -> Boolean = { true },
        realm: String?,
    ) : this(
        refreshTokens,
        loadTokens,
        sendWithoutRequestCallback,
        realm,
        cacheTokens = true,
        nonCancellableRefresh = false
    )

    @Suppress("OverridingDeprecatedMember")
    @Deprecated("Please use sendWithoutRequest function instead", level = DeprecationLevel.ERROR)
    override val sendWithoutRequest: Boolean
        get() = error("Deprecated")

Review comment (suggestion):
I think only one of these constructors is required
```suggestion
    @Deprecated("Maintained for binary compatibility", level = DeprecationLevel.HIDDEN)
    public constructor(
```

Code after:
     * [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.client.plugins.auth.BearerAuthConfig.nonCancellableRefresh)
     */
    public var nonCancellableRefresh: Boolean = false
}

/**
 * An authentication provider for the Bearer HTTP authentication scheme.
 * Bearer authentication involves security tokens called bearer tokens.
 * As an example, these tokens can be used as a part of OAuth flow to authorize users of your application
 * by using external providers, such as Google, Facebook, Twitter, and so on.
 *
 * You can learn more from [Bearer authentication](https://ktor.io/docs/bearer-client.html).
 *
 * [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.client.plugins.auth.providers.BearerAuthProvider)
 */
public class BearerAuthProvider(
    private val refreshTokens: suspend RefreshTokensParams.() -> BearerTokens?,
    loadTokens: suspend () -> BearerTokens?,
    private val sendWithoutRequestCallback: (HttpRequestBuilder) -> Boolean = { true },
    private val realm: String?,
    cacheTokens: Boolean = true,
    private val nonCancellableRefresh: Boolean = false,
) : AuthProvider {

    @Deprecated("Maintained for binary compatibility", level = DeprecationLevel.HIDDEN)
    public constructor(
        refreshTokens: suspend (RefreshTokensParams) -> BearerTokens?,
        loadTokens: suspend () -> BearerTokens?,
        sendWithoutRequestCallback: (HttpRequestBuilder) -> Boolean = { true },
        realm: String?,
    ) : this(
        refreshTokens,
        loadTokens,
        sendWithoutRequestCallback,
        realm,
        cacheTokens = true,
        nonCancellableRefresh = false
    )

    @Suppress("OverridingDeprecatedMember")
    @Deprecated("Please use sendWithoutRequest function instead", level = DeprecationLevel.ERROR)
    override val sendWithoutRequest: Boolean
        get() = error("Deprecated")

    private val tokensHolder = AuthTokenHolder(loadTokens, cacheTokens)

    override fun sendWithoutRequest(request: HttpRequestBuilder): Boolean = sendWithoutRequestCallback(request)

    /**
     * Checks if current provider is applicable to the request.
     *