Skip to content

Commit

Permalink
Google cloud storage client (#588)
Browse files Browse the repository at this point in the history
Bump jwt-core to 3.0.1
  • Loading branch information
jkobejs committed Jun 21, 2019
1 parent 1412c24 commit 066d265
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ import scala.util.control.NonFatal
val uri = uriFactory(conf)
val request = HttpRequest(method)
.withUri(uri)
.withHeaders(headers: _*)
.withHeaders(headers.toList)

createAuthenticatedRequestSource(request)
}
Expand All @@ -351,7 +351,7 @@ import scala.util.control.NonFatal
val request = HttpRequest(HttpMethods.POST)
.withUri(uri)
.withEntity(contentType, bytes)
.withHeaders(headers: _*)
.withHeaders(headers.toList)

createAuthenticatedRequestSource(request)
}
Expand All @@ -367,7 +367,7 @@ import scala.util.control.NonFatal
val uri = uriFactory(conf)
val request = HttpRequest(HttpMethods.POST)
.withUri(uri)
.withHeaders(headers: _*)
.withHeaders(headers.toList)

createAuthenticatedRequestSource(request)
}
Expand All @@ -386,7 +386,7 @@ import scala.util.control.NonFatal
val request = HttpRequest(HttpMethods.POST)
.withUri(uri)
.withEntity(HttpEntity(contentType, data))
.withHeaders(headers: _*)
.withHeaders(headers.toList)

createAuthenticatedRequestSource(request)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import akka.stream.alpakka.googlecloud.storage.impl.GoogleTokenApi.{AccessTokenE
import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim, JwtTime}
import spray.json.{DefaultJsonProtocol, RootJsonFormat}

import java.time.Clock
import scala.concurrent.Future

@InternalApi
private[impl] class GoogleTokenApi(http: => HttpExt, settings: TokenApiSettings) {
implicit val clock: Clock = Clock.systemUTC

protected val encodingAlgorithm: JwtAlgorithm.RS256.type = JwtAlgorithm.RS256

def now: Long = JwtTime.nowSeconds
Expand Down
24 changes: 16 additions & 8 deletions google-cloud-storage/src/test/resources/application.conf
Original file line number Diff line number Diff line change
Expand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amm
OAAzIwJBANV2GAD5HaHDShK/ZTf4dxjWM+pDnSVKnUJPS039EUKdC8cK2RiGjGNA
v3jdg1Tw2cE1K8QhJwN8qOFj4JBWVbECQQCwcntej9bnf4vi1wd1YnCHkJyRqQIS
7974DhNGfYAQPv5w1JwtCRSuKuJvH1w0R1ijd//scjCNfQKgpNXPRbzpAkAQ8MFA
MLpOLGqezUQthJWmVtnXEXaAlb3yFSRTZQVEselObiIc6EvYzNXv780IDT4pyKjg
8DS9i5jJDIVWr7mA
-----END PRIVATE KEY-----
"""
privateKey = ${?GC_STORAGE_PRIVATE_KEY}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,35 @@ class GoogleTokenApiSpec extends WordSpecLike with Matchers with ScalaFutures wi
override def afterAll(): Unit =
Await.result(system.terminate(), 5.seconds)

//http://travistidwell.com/jsencrypt/demo/
// openssl genrsa -out mykey.pem 1024
// openssl pkcs8 -topk8 -nocrypt -in mykey.pem -out myrsakey_pcks8
// openssl rsa -in mykey.pem -pubout > mykey.pub
val privateKey =
"""-----BEGIN RSA PRIVATE KEY-----
|MIIBOgIBAAJBAJHPYfmEpShPxAGP12oyPg0CiL1zmd2V84K5dgzhR9TFpkAp2kl2
|9BTc8jbAY0dQW4Zux+hyKxd6uANBKHOWacUCAwEAAQJAQVyXbMS7TGDFWnXieKZh
|Dm/uYA6sEJqheB4u/wMVshjcQdHbi6Rr0kv7dCLbJz2v9bVmFu5i8aFnJy1MJOpA
|2QIhAPyEAaVfDqJGjVfryZDCaxrsREmdKDlmIppFy78/d8DHAiEAk9JyTHcapckD
|uSyaE6EaqKKfyRwSfUGO1VJXmPjPDRMCIF9N900SDnTiye/4FxBiwIfdynw6K3dW
|fBLb6uVYr/r7AiBUu/p26IMm6y4uNGnxvJSqe+X6AxR6Jl043OWHs4AEbwIhANuz
|Ay3MKOeoVbx0L+ruVRY5fkW+oLHbMGtQ9dZq7Dp9
|-----END RSA PRIVATE KEY-----""".stripMargin

val publicKey =
"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ATE KEY-----
""".stripMargin

val publicKey = """-----BEGIN PUBLIC KEY-----
|MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMJJncK1qfiy5bH21RPp3hY2bV
|Dbmg+P7aUNlCIdrvqlOrK+GxvDz7qkna7eW9P9L3zGQNdZkFpiqYOTyvfJBJIW0r
|wtPHxtE7aUffr35YITrrr3MOpAp4sDWx5Tl5xPA8LSkKdQ201D8zA4YbCIyWlLb9
|fV5O4IeDKmIADU5upQIDAQAB
|-----END PUBLIC KEY-----
""".stripMargin

private val settings = TokenApiSettings(
url = "https://www.googleapis.com/oauth2/v4/token",
Expand Down Expand Up @@ -92,9 +104,10 @@ class GoogleTokenApiSpec extends WordSpecLike with Matchers with ScalaFutures wi
val jwt = data.replace("grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=", "")
val decoded = Jwt.decode(jwt, publicKey, Seq(JwtAlgorithm.RS256))
decoded.isSuccess shouldBe true
decoded.get should include(""""aud":"https://www.googleapis.com/oauth2/v4/token"""")
decoded.get should include(""""scope":"https://www.googleapis.com/auth/devstorage.read_write"""")
decoded.get should include(""""iss":"email"""")
val claimsJson = decoded.get.toJson
claimsJson should include(""""aud":"https://www.googleapis.com/oauth2/v4/token"""")
claimsJson should include(""""scope":"https://www.googleapis.com/auth/devstorage.read_write"""")
claimsJson should include("email")

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,22 @@ object GCStorageWiremockBase {
| project-id = ""testX-XXXXX""
| client-email = "[email protected]"
| private-key = \"\"\"
|MIIBOgIBAAJBAJHPYfmEpShPxAGP12oyPg0CiL1zmd2V84K5dgzhR9TFpkAp2kl2
|9BTc8jbAY0dQW4Zux+hyKxd6uANBKHOWacUCAwEAAQJAQVyXbMS7TGDFWnXieKZh
|Dm/uYA6sEJqheB4u/wMVshjcQdHbi6Rr0kv7dCLbJz2v9bVmFu5i8aFnJy1MJOpA
|2QIhAPyEAaVfDqJGjVfry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NXv780IDT4pyKjg
|8DS9i5jJDIVWr7mA
|-----END PRIVATE KEY-----
|\"\"\"
| base-url = "http://localhost:${proxyPort}"
| base-path = ""
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object Dependencies {
val CouchbaseVersion = "2.7.2"
val CouchbaseVersionForDocs = "2.7"

val JwtCoreVersion = "2.1.0"
val JwtCoreVersion = "3.0.1"

// Allows to silence scalac compilation warnings selectively by code block or file path
// This is only compile time dependency, therefore it does not affect the generated bytecode
Expand Down

0 comments on commit 066d265

Please sign in to comment.