package auth
Provides access to authethentication types and 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.RequestMethods.GET import scamper.ResponseStatuses.Unauthorized import scamper.auth.{ Authorization, Challenge, Credentials, WwwAuthenticate } // Present response challenge (scheme and parameters) val challenge = Challenge("Bearer", "realm" -> "developer") val res = Unauthorized().withWwwAuthenticate(challenge) // Present request credentials (scheme and token) val credentials = Credentials("Bearer", "QWxsIEFjY2VzcyEhIQo=") val req = GET("/dev/projects").withAuthorization(credentials)
Basic Authentication
There are subclasses defined for Basic authentication: BasicChallenge
and
BasicCredentials
.
import scamper.Implicits.stringToUri import scamper.RequestMethods.GET import scamper.ResponseStatuses.Unauthorized import scamper.auth.{ Authorization, BasicChallenge, BasicCredentials, WwwAuthenticate } // Provide realm and optional parameters val challenge = BasicChallenge("admin", "title" -> "Admin Console") val res = Unauthorized().withWwwAuthenticate(challenge) // Provide user and password val credentials = BasicCredentials("sa", "l3tm31n") val req = GET("/admin/users").withAuthorization(credentials)
In addition, there are methods for Basic authentication defined in the header classes.
import scamper.Implicits.stringToUri import scamper.RequestMethods.GET import scamper.ResponseStatuses.Unauthorized import scamper.auth.{ Authorization, WwwAuthenticate } // Provide realm and optional parameters val res = Unauthorized().withBasic("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").withBasic("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
. And, similar to Basic, there are Bearer-specific methods
available in the header classes.
import scamper.Implicits.stringToUri import scamper.RequestMethods.GET import scamper.ResponseStatuses.Unauthorized import scamper.auth.{ Authorization, WwwAuthenticate } // Provide challenge parameters val res = Unauthorized().withBearer( "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").withBearer("R290IDUgb24gaXQhCg==")
- Alphabetic
- By Inheritance
- auth
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
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
Factory for BasicChallenge.
-
object
BasicCredentials
Factory for BasicCredentials.
-
object
BearerChallenge
Factory for BearerChallenge.
-
object
BearerCredentials
Factory for BearerCredentials.
-
object
Challenge
Challenge factory
-
object
Credentials
Credentials factory