Merge pull request #220 from alexarchambault/header-based-auth

Allow authenticating via custom HTTP headers
This commit is contained in:
Alexandre Archambault 2020-05-04 12:38:31 +02:00 committed by GitHub
commit f336c89561
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

7
.gitignore vendored
View File

@ -1 +1,8 @@
target/
# Metals / bloop
.metals/
.bloop/
# Intellij
.idea/

View File

@ -75,6 +75,8 @@ import scala.concurrent.duration.Duration
withStrict(Some(strict))
def withTtl(ttl: Duration): CoursierConfiguration =
withTtl(Some(ttl))
def addRepositoryAuthentication(repositoryId: String, authentication: Authentication): CoursierConfiguration =
withAuthenticationByRepositoryId(authenticationByRepositoryId :+ (repositoryId, authentication))
}
object CoursierConfiguration {

View File

@ -1,15 +1,30 @@
package lmcoursier.definitions
import dataclass.data
import dataclass._
@data class Authentication(
user: String,
password: String,
optional: Boolean = false,
realmOpt: Option[String] = None
realmOpt: Option[String] = None,
@since
headers: Seq[(String,String)] = Nil,
httpsOnly: Boolean = true,
passOnRedirect: Boolean = false
) {
override def toString(): String =
withPassword("****")
.withHeaders(
headers.map {
case (k, v) => (k, "****")
}
)
.productIterator
.mkString("Authentication(", ", ", ")")
}
object Authentication {
def apply(headers: Seq[(String, String)]): Authentication =
Authentication("", "").withHeaders(headers)
}

View File

@ -27,6 +27,9 @@ object ToCoursier {
coursier.core.Authentication(authentication.user, authentication.password)
.withOptional(authentication.optional)
.withRealmOpt(authentication.realmOpt)
.withHttpHeaders(authentication.headers)
.withHttpsOnly(authentication.httpsOnly)
.withPassOnRedirect(authentication.passOnRedirect)
def module(module: Module): coursier.core.Module =
coursier.core.Module(