package auth
Provides specialized access to authentication headers.
Challenges and Credentials
When working with authentication, a Challenge
is presented in the response,
and Credentials
in the request. Each of these has an assigned scheme, which
is associated with either a token or a set of parameters.
import scamper.Implicits.stringToUri import scamper.RequestMethod.Registry.Get import scamper.ResponseStatus.Registry.Unauthorized import scamper.auth.{ Authorization, Challenge, Credentials, WwwAuthenticate } // Present response challenge (scheme and parameters) val challenge = Challenge("Bearer", "realm" -> "developer") val res = Unauthorized().setWwwAuthenticate(challenge) // Present request credentials (scheme and token) val credentials = Credentials("Bearer", "QWxsIEFjY2VzcyEhIQo=") val req = Get("/dev/projects").setAuthorization(credentials)
Basic Authentication
There are subclasses defined for Basic authentication: BasicChallenge
and
BasicCredentials
.
import scamper.Implicits.stringToUri import scamper.RequestMethod.Registry.Get import scamper.ResponseStatus.Registry.Unauthorized import scamper.auth.{ Authorization, BasicChallenge, BasicCredentials, WwwAuthenticate } // Provide realm and optional parameters val challenge = BasicChallenge("admin", "title" -> "Admin Console") val res = Unauthorized().setWwwAuthenticate(challenge) // Provide user and password val credentials = BasicCredentials("sa", "l3tm31n") val req = Get("/admin/users").setAuthorization(credentials)
In addition, there are methods for Basic authentication defined in the header classes.
import scamper.Implicits.stringToUri import scamper.RequestMethod.Registry.Get import scamper.ResponseStatus.Registry.Unauthorized import scamper.auth.{ Authorization, WwwAuthenticate } // Provide realm and optional parameters val res = Unauthorized().setBasic("admin", "title" -> "Admin Console") // Access basic auth in response printf(s"Realm: %s%n", res.basic.realm) printf(s"Title: %s%n", res.basic.params("title")) // Provide user and password val req = Get("/admin/users").setBasic("sa", "l3tm3m1n") // Access basic auth in request printf(s"User: %s%n", req.basic.user) printf(s"Password: %s%n", req.basic.password)
Bearer Authentication
There are subclasses defined for Bearer authentication: BearerChallenge
and
BearerCredentials
. In addition, there are Bearer-specific methods available
in the header classes.
import scamper.Implicits.stringToUri import scamper.RequestMethod.Registry.Get import scamper.ResponseStatus.Registry.Unauthorized import scamper.auth.{ Authorization, WwwAuthenticate } // Provide challenge parameters val res = Unauthorized().setBearer( "scope" -> "user profile", "error" -> "invalid_token", "error_description" -> "Expired access token" ) // Print optional realm parameter res.bearer.realm.foreach(println) // Print scope from space-delimited parameter val scope: Seq[String] = res.bearer.scope scope.foreach(println) // Print error parameters res.bearer.error.foreach(println) res.bearer.errorDescription.foreach(println) res.bearer.errorUri.foreach(println) // Test for error conditions println(res.bearer.isInvalidToken) println(res.bearer.isInvalidRequest) println(res.bearer.isInsufficientScope) // Create request with Bearer token val req = Get("/users").setBearer("R290IDUgb24gaXQhCg==") // Access bearer auth in request printf("Token: %s%n", req.bearer.token)
- Alphabetic
- By Inheritance
- auth
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
sealed
trait
AuthType extends AnyRef
Base type for authentication header types.
-
implicit final
class
AuthenticationInfo extends AnyVal
Provides standardized access to Authentication-Info header.
-
implicit final
class
Authorization extends AnyVal
Provides standardized access to Authorization header.
-
trait
BasicChallenge extends Challenge
Challenge for Basic authentication.
-
trait
BasicCredentials extends Credentials
Credentials for Basic authorization.
-
trait
BearerChallenge extends Challenge
Challenge for Bearer authentication.
-
trait
BearerCredentials extends Credentials
Credentials for Bearer authorization.
-
trait
Challenge extends AuthType
Standardized type for WWW-Authenticate and Proxy-Authenticate header value.
Standardized type for WWW-Authenticate and Proxy-Authenticate header value.
-
trait
Credentials extends AuthType
Standardized type for Authorization and Proxy-Authorization header value.
Standardized type for Authorization and Proxy-Authorization header value.
-
implicit final
class
ProxyAuthenticate extends AnyVal
Provides standardized access to Proxy-Authenticate header.
-
implicit final
class
ProxyAuthenticationInfo extends AnyVal
Provides standardized access to Proxy-Authentication-Info header.
-
implicit final
class
ProxyAuthorization extends AnyVal
Provides standardized access to Proxy-Authorization header.
-
implicit final
class
WwwAuthenticate extends AnyVal
Provides standardized access to WWW-Authenticate header.
Value Members
-
implicit
val
stringToChallenge: (String) ⇒ Challenge
Converts string to Challenge.
-
implicit
val
stringToCredentials: (String) ⇒ Credentials
Converts string to Credentials.
-
object
BasicChallenge
Provides factory for
BasicChallenge
. -
object
BasicCredentials
Provides factory for
BasicCredentials
. -
object
BearerChallenge
Provides factory for
BearerChallenge
. -
object
BearerCredentials
Provides factory for
BearerCredentials
. -
object
Challenge
Provides factory for
Challenge
. -
object
Credentials
Provides factory for
Credentials
.
Provided herein is API documentation for Scamper, the HTTP library for Scala.