sttp-scribe


License

License

GroupId

GroupId

software.purpledragon
ArtifactId

ArtifactId

sttp-scribe_2.13
Last Version

Last Version

2.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

sttp-scribe
sttp-scribe
Project URL

Project URL

https://github.com/stringbean/sttp-scribe
Project Organization

Project Organization

Purple Dragon Software
Source Code Management

Source Code Management

https://github.com/stringbean/sttp-scribe

Download sttp-scribe_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/software.purpledragon/sttp-scribe_2.13/ -->
<dependency>
    <groupId>software.purpledragon</groupId>
    <artifactId>sttp-scribe_2.13</artifactId>
    <version>2.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/software.purpledragon/sttp-scribe_2.13/
implementation 'software.purpledragon:sttp-scribe_2.13:2.0.2'
// https://jarcasting.com/artifacts/software.purpledragon/sttp-scribe_2.13/
implementation ("software.purpledragon:sttp-scribe_2.13:2.0.2")
'software.purpledragon:sttp-scribe_2.13:jar:2.0.2'
<dependency org="software.purpledragon" name="sttp-scribe_2.13" rev="2.0.2">
  <artifact name="sttp-scribe_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='software.purpledragon', module='sttp-scribe_2.13', version='2.0.2')
)
libraryDependencies += "software.purpledragon" % "sttp-scribe_2.13" % "2.0.2"
[software.purpledragon/sttp-scribe_2.13 "2.0.2"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.2
org.slf4j : slf4j-api jar 1.7.26
com.softwaremill.sttp.client : core_2.13 jar 2.1.2
com.github.scribejava : scribejava-apis jar 6.9.0
com.github.bigwheel : util-backports_2.13 jar 2.1

test (6)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.1.2
org.scalamock : scalamock_2.13 jar 4.4.0
org.scala-lang.modules : scala-collection-compat_2.13 jar 2.1.6
commons-io : commons-io jar 2.7
org.apache.commons : commons-lang3 jar 3.10
ch.qos.logback : logback-classic jar 1.2.3

Project Modules

There are no modules declared in this project.

sttp-scribe - sttp backend for ScribeJava

Build Status Codacy Grade Test Coverage Maven Central - Scala 2.11 Maven Central - Scala 2.12 Maven Central - Scala 2.13

A backend implementation for sttp that allows you to use ScribeJava as a backend. Now you can call OAuth endpoints using sttp!

Quickstart

Add sttp-scribe, sttp and Scribe to your project:

libraryDependencies ++= Seq(
  "software.purpledragon"         %% "sttp-scribe"      % <version>,
  "com.softwaremill.sttp.client"  %% "core"             % "2.1.2",
  "com.github.scribejava"         %  "scribejava-apis"  % "6.9.0",    
)

Setup your Scribe service:

val service = new ServiceBuilder("api-key")
  .apiSecret("api-secret")
  .callback("http://www.example.com/oauth_callback/")
  .build(GitHubApi.instance());

Create a token provider:

val tokenProvider = new OAuth2TokenProvider() {
  private var currentToken: Option[OAuth2AccessToken] = None

  override def accessTokenForRequest: OAuth2AccessToken = {
    currentToken.getOrElse { 
      // fetch from DB or another source
    }
  }

  override def tokenRenewed(newToken: OAuth2AccessToken): Unit = {
    currentToken = Some(newToken)
    // persist token to DB
  }
}

Then create a ScribeOAuth20Backend and use sttp to make authenticated calls:

implicit val backend: SttpBackend[Identity, Nothing, NothingT] = 
  new ScribeOAuth20Backend(service, tokenProvider)

val response = basicRequest
  .get(uri"https://api.github.com/users/octocat")
  .send()

The Scribe backend will take care of refreshing the access token when it expires and retrying the current API call.

Versions

Version
2.0.2
2.0.1
2.0.0
1.6.0
1.5.2
1.5.1
1.5.0
1.4.0
1.3.1