use std::fmt::{Display, Error as FormatterError, Formatter};
use std::ops::Deref;
pub use oauth2::basic::{
BasicErrorResponseType as CoreErrorResponseType,
BasicRequestTokenError as CoreRequestTokenError,
BasicRevocationErrorResponse as CoreRevocationErrorResponse, BasicTokenType as CoreTokenType,
};
use oauth2::devicecode::{DeviceAuthorizationResponse, EmptyExtraDeviceAuthorizationFields};
pub use oauth2::StandardRevocableToken as CoreRevocableToken;
use oauth2::{
EmptyExtraTokenFields, ErrorResponseType, ResponseType as OAuth2ResponseType,
StandardErrorResponse, StandardTokenIntrospectionResponse, StandardTokenResponse,
};
use serde::{Deserialize, Serialize};
use crate::registration::{
ClientMetadata, ClientRegistrationRequest, ClientRegistrationResponse,
EmptyAdditionalClientMetadata, EmptyAdditionalClientRegistrationResponse,
RegisterErrorResponseType,
};
use crate::{
ApplicationType, AuthDisplay, AuthPrompt, ClaimName, ClaimType, Client, ClientAuthMethod,
EmptyAdditionalClaims, EmptyAdditionalProviderMetadata, GenderClaim, GrantType, IdToken,
IdTokenClaims, IdTokenFields, IdTokenVerifier, JsonWebKeySet, JweContentEncryptionAlgorithm,
JweKeyManagementAlgorithm, JwsSigningAlgorithm, ProviderMetadata, ResponseMode, ResponseType,
SubjectIdentifierType, UserInfoClaims, UserInfoJsonWebToken, UserInfoVerifier,
};
use super::AuthenticationFlow;
pub use self::jwk::{
CoreEdDsaPrivateSigningKey, CoreHmacKey, CoreJsonWebKey, CoreJsonWebKeyType, CoreJsonWebKeyUse,
CoreRsaPrivateSigningKey,
};
mod crypto;
mod jwk;
pub type CoreDeviceAuthorizationResponse =
DeviceAuthorizationResponse<EmptyExtraDeviceAuthorizationFields>;
pub type CoreTokenIntrospectionResponse =
StandardTokenIntrospectionResponse<EmptyExtraTokenFields, CoreTokenType>;
pub type CoreAuthenticationFlow = AuthenticationFlow<CoreResponseType>;
pub type CoreClient = Client<
EmptyAdditionalClaims,
CoreAuthDisplay,
CoreGenderClaim,
CoreJweContentEncryptionAlgorithm,
CoreJwsSigningAlgorithm,
CoreJsonWebKeyType,
CoreJsonWebKeyUse,
CoreJsonWebKey,
CoreAuthPrompt,
StandardErrorResponse<CoreErrorResponseType>,
CoreTokenResponse,
CoreTokenType,
CoreTokenIntrospectionResponse,
CoreRevocableToken,
CoreRevocationErrorResponse,
>;
pub type CoreClientMetadata = ClientMetadata<
EmptyAdditionalClientMetadata,
CoreApplicationType,
CoreClientAuthMethod,
CoreGrantType,
CoreJweContentEncryptionAlgorithm,
CoreJweKeyManagementAlgorithm,
CoreJwsSigningAlgorithm,
CoreJsonWebKeyType,
CoreJsonWebKeyUse,
CoreJsonWebKey,
CoreResponseType,
CoreSubjectIdentifierType,
>;
pub type CoreClientRegistrationRequest = ClientRegistrationRequest<
EmptyAdditionalClientMetadata,
EmptyAdditionalClientRegistrationResponse,
CoreApplicationType,
CoreClientAuthMethod,
CoreRegisterErrorResponseType,
CoreGrantType,
CoreJweContentEncryptionAlgorithm,
CoreJweKeyManagementAlgorithm,
CoreJwsSigningAlgorithm,
CoreJsonWebKeyType,
CoreJsonWebKeyUse,
CoreJsonWebKey,
CoreResponseType,
CoreSubjectIdentifierType,
>;
pub type CoreClientRegistrationResponse = ClientRegistrationResponse<
EmptyAdditionalClientMetadata,
EmptyAdditionalClientRegistrationResponse,
CoreApplicationType,
CoreClientAuthMethod,
CoreGrantType,
CoreJweContentEncryptionAlgorithm,
CoreJweKeyManagementAlgorithm,
CoreJwsSigningAlgorithm,
CoreJsonWebKeyType,
CoreJsonWebKeyUse,
CoreJsonWebKey,
CoreResponseType,
CoreSubjectIdentifierType,
>;
pub type CoreIdToken = IdToken<
EmptyAdditionalClaims,
CoreGenderClaim,
CoreJweContentEncryptionAlgorithm,
CoreJwsSigningAlgorithm,
CoreJsonWebKeyType,
>;
pub type CoreIdTokenClaims = IdTokenClaims<EmptyAdditionalClaims, CoreGenderClaim>;
pub type CoreIdTokenFields = IdTokenFields<
EmptyAdditionalClaims,
EmptyExtraTokenFields,
CoreGenderClaim,
CoreJweContentEncryptionAlgorithm,
CoreJwsSigningAlgorithm,
CoreJsonWebKeyType,
>;
pub type CoreIdTokenVerifier<'a> = IdTokenVerifier<
'a,
CoreJwsSigningAlgorithm,
CoreJsonWebKeyType,
CoreJsonWebKeyUse,
CoreJsonWebKey,
>;
pub type CoreTokenResponse = StandardTokenResponse<CoreIdTokenFields, CoreTokenType>;
pub type CoreJsonWebKeySet =
JsonWebKeySet<CoreJwsSigningAlgorithm, CoreJsonWebKeyType, CoreJsonWebKeyUse, CoreJsonWebKey>;
pub type CoreProviderMetadata = ProviderMetadata<
EmptyAdditionalProviderMetadata,
CoreAuthDisplay,
CoreClientAuthMethod,
CoreClaimName,
CoreClaimType,
CoreGrantType,
CoreJweContentEncryptionAlgorithm,
CoreJweKeyManagementAlgorithm,
CoreJwsSigningAlgorithm,
CoreJsonWebKeyType,
CoreJsonWebKeyUse,
CoreJsonWebKey,
CoreResponseMode,
CoreResponseType,
CoreSubjectIdentifierType,
>;
pub type CoreUserInfoClaims = UserInfoClaims<EmptyAdditionalClaims, CoreGenderClaim>;
pub type CoreUserInfoJsonWebToken = UserInfoJsonWebToken<
EmptyAdditionalClaims,
CoreGenderClaim,
CoreJweContentEncryptionAlgorithm,
CoreJwsSigningAlgorithm,
CoreJsonWebKeyType,
>;
pub type CoreUserInfoVerifier<'a> = UserInfoVerifier<
'a,
CoreJweContentEncryptionAlgorithm,
CoreJwsSigningAlgorithm,
CoreJsonWebKeyType,
CoreJsonWebKeyUse,
CoreJsonWebKey,
>;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CoreApplicationType {
Native,
Web,
Extension(String),
}
deserialize_from_str!(CoreApplicationType);
serialize_as_str!(CoreApplicationType);
impl CoreApplicationType {
fn from_str(s: &str) -> Self {
match s {
"native" => CoreApplicationType::Native,
"web" => CoreApplicationType::Web,
ext => CoreApplicationType::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreApplicationType {
fn as_ref(&self) -> &str {
match *self {
CoreApplicationType::Native => "native",
CoreApplicationType::Web => "web",
CoreApplicationType::Extension(ref ext) => ext.as_str(),
}
}
}
impl ApplicationType for CoreApplicationType {}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CoreAuthDisplay {
Page,
Popup,
Touch,
Wap,
Extension(String),
}
deserialize_from_str!(CoreAuthDisplay);
serialize_as_str!(CoreAuthDisplay);
impl CoreAuthDisplay {
fn from_str(s: &str) -> Self {
match s {
"page" => CoreAuthDisplay::Page,
"popup" => CoreAuthDisplay::Popup,
"touch" => CoreAuthDisplay::Touch,
"wap" => CoreAuthDisplay::Wap,
ext => CoreAuthDisplay::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreAuthDisplay {
fn as_ref(&self) -> &str {
match *self {
CoreAuthDisplay::Page => "page",
CoreAuthDisplay::Popup => "popup",
CoreAuthDisplay::Touch => "touch",
CoreAuthDisplay::Wap => "wap",
CoreAuthDisplay::Extension(ref ext) => ext.as_str(),
}
}
}
impl AuthDisplay for CoreAuthDisplay {}
impl Display for CoreAuthDisplay {
fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
write!(f, "{}", self.as_ref())
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CoreAuthPrompt {
None,
Login,
Consent,
SelectAccount,
Extension(String),
}
deserialize_from_str!(CoreAuthPrompt);
serialize_as_str!(CoreAuthPrompt);
impl CoreAuthPrompt {
fn from_str(s: &str) -> Self {
match s {
"none" => CoreAuthPrompt::None,
"login" => CoreAuthPrompt::Login,
"consent" => CoreAuthPrompt::Consent,
"select_account" => CoreAuthPrompt::SelectAccount,
ext => CoreAuthPrompt::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreAuthPrompt {
fn as_ref(&self) -> &str {
match *self {
CoreAuthPrompt::None => "none",
CoreAuthPrompt::Login => "login",
CoreAuthPrompt::Consent => "consent",
CoreAuthPrompt::SelectAccount => "select_account",
CoreAuthPrompt::Extension(ref ext) => ext.as_str(),
}
}
}
impl AuthPrompt for CoreAuthPrompt {}
impl Display for CoreAuthPrompt {
fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
write!(f, "{}", self.as_ref())
}
}
new_type![
#[derive(Deserialize, Eq, Hash, Ord, PartialOrd, Serialize)]
CoreClaimName(String)
];
impl ClaimName for CoreClaimName {}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CoreClaimType {
Aggregated,
Distributed,
Normal,
Extension(String),
}
deserialize_from_str!(CoreClaimType);
serialize_as_str!(CoreClaimType);
impl CoreClaimType {
fn from_str(s: &str) -> Self {
match s {
"normal" => CoreClaimType::Normal,
"aggregated" => CoreClaimType::Aggregated,
"distributed" => CoreClaimType::Distributed,
ext => CoreClaimType::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreClaimType {
fn as_ref(&self) -> &str {
match *self {
CoreClaimType::Normal => "normal",
CoreClaimType::Aggregated => "aggregated",
CoreClaimType::Distributed => "distributed",
CoreClaimType::Extension(ref ext) => ext.as_str(),
}
}
}
impl ClaimType for CoreClaimType {}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CoreClientAuthMethod {
ClientSecretBasic,
ClientSecretJwt,
ClientSecretPost,
PrivateKeyJwt,
None,
Extension(String),
}
deserialize_from_str!(CoreClientAuthMethod);
serialize_as_str!(CoreClientAuthMethod);
impl CoreClientAuthMethod {
fn from_str(s: &str) -> Self {
match s {
"client_secret_basic" => CoreClientAuthMethod::ClientSecretBasic,
"client_secret_jwt" => CoreClientAuthMethod::ClientSecretJwt,
"client_secret_post" => CoreClientAuthMethod::ClientSecretPost,
"private_key_jwt" => CoreClientAuthMethod::PrivateKeyJwt,
"none" => CoreClientAuthMethod::None,
ext => CoreClientAuthMethod::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreClientAuthMethod {
fn as_ref(&self) -> &str {
match *self {
CoreClientAuthMethod::ClientSecretBasic => "client_secret_basic",
CoreClientAuthMethod::ClientSecretJwt => "client_secret_jwt",
CoreClientAuthMethod::ClientSecretPost => "client_secret_post",
CoreClientAuthMethod::PrivateKeyJwt => "private_key_jwt",
CoreClientAuthMethod::None => "none",
CoreClientAuthMethod::Extension(ref ext) => ext.as_str(),
}
}
}
impl ClientAuthMethod for CoreClientAuthMethod {}
new_type![
#[derive(Deserialize, Eq, Hash, Ord, PartialOrd, Serialize)]
CoreGenderClaim(String)
];
impl GenderClaim for CoreGenderClaim {}
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum CoreGrantType {
AuthorizationCode,
ClientCredentials,
DeviceCode,
Implicit,
JwtBearer,
Password,
RefreshToken,
Extension(String),
}
deserialize_from_str!(CoreGrantType);
serialize_as_str!(CoreGrantType);
impl CoreGrantType {
fn from_str(s: &str) -> Self {
match s {
"authorization_code" => CoreGrantType::AuthorizationCode,
"client_credentials" => CoreGrantType::ClientCredentials,
"urn:ietf:params:oauth:grant-type:device_code" => CoreGrantType::DeviceCode,
"implicit" => CoreGrantType::Implicit,
"urn:ietf:params:oauth:grant-type:jwt-bearer" => CoreGrantType::JwtBearer,
"password" => CoreGrantType::Password,
"refresh_token" => CoreGrantType::RefreshToken,
ext => CoreGrantType::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreGrantType {
fn as_ref(&self) -> &str {
match *self {
CoreGrantType::AuthorizationCode => "authorization_code",
CoreGrantType::ClientCredentials => "client_credentials",
CoreGrantType::DeviceCode => "urn:ietf:params:oauth:grant-type:device_code",
CoreGrantType::Implicit => "implicit",
CoreGrantType::JwtBearer => "urn:ietf:params:oauth:grant-type:jwt-bearer",
CoreGrantType::Password => "password",
CoreGrantType::RefreshToken => "refresh_token",
CoreGrantType::Extension(ref ext) => ext.as_str(),
}
}
}
impl GrantType for CoreGrantType {}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
pub enum CoreJweContentEncryptionAlgorithm {
#[serde(rename = "A128CBC-HS256")]
Aes128CbcHmacSha256,
#[serde(rename = "A192CBC-HS384")]
Aes192CbcHmacSha384,
#[serde(rename = "A256CBC-HS512")]
Aes256CbcHmacSha512,
#[serde(rename = "A128GCM")]
Aes128Gcm,
#[serde(rename = "A192GCM")]
Aes192Gcm,
#[serde(rename = "A256GCM")]
Aes256Gcm,
}
impl JweContentEncryptionAlgorithm<CoreJsonWebKeyType> for CoreJweContentEncryptionAlgorithm {
fn key_type(&self) -> Result<CoreJsonWebKeyType, String> {
Ok(CoreJsonWebKeyType::Symmetric)
}
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
pub enum CoreJweKeyManagementAlgorithm {
#[serde(rename = "RSA1_5")]
RsaPkcs1V15,
#[serde(rename = "RSA-OAEP")]
RsaOaep,
#[serde(rename = "RSA-OAEP-256")]
RsaOaepSha256,
#[serde(rename = "A128KW")]
AesKeyWrap128,
#[serde(rename = "A192KW")]
AesKeyWrap192,
#[serde(rename = "A256KW")]
AesKeyWrap256,
#[serde(rename = "dir")]
Direct,
#[serde(rename = "ECDH-ES")]
EcdhEs,
#[serde(rename = "ECDH-ES+A128KW")]
EcdhEsAesKeyWrap128,
#[serde(rename = "ECDH-ES+A192KW")]
EcdhEsAesKeyWrap192,
#[serde(rename = "ECDH-ES+A256KW")]
EcdhEsAesKeyWrap256,
#[serde(rename = "A128GCMKW")]
Aes128Gcm,
#[serde(rename = "A192GCMKW")]
Aes192Gcm,
#[serde(rename = "A256GCMKW")]
Aes256Gcm,
#[serde(rename = "PBES2-HS256+A128KW")]
PbEs2HmacSha256AesKeyWrap128,
#[serde(rename = "PBES2-HS384+A192KW")]
PbEs2HmacSha384AesKeyWrap192,
#[serde(rename = "PBES2-HS512+A256KW")]
PbEs2HmacSha512AesKeyWrap256,
}
impl JweKeyManagementAlgorithm for CoreJweKeyManagementAlgorithm {}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
pub enum CoreJwsSigningAlgorithm {
#[serde(rename = "HS256")]
HmacSha256,
#[serde(rename = "HS384")]
HmacSha384,
#[serde(rename = "HS512")]
HmacSha512,
#[serde(rename = "RS256")]
RsaSsaPkcs1V15Sha256,
#[serde(rename = "RS384")]
RsaSsaPkcs1V15Sha384,
#[serde(rename = "RS512")]
RsaSsaPkcs1V15Sha512,
#[serde(rename = "ES256")]
EcdsaP256Sha256,
#[serde(rename = "ES384")]
EcdsaP384Sha384,
#[serde(rename = "ES512")]
EcdsaP521Sha512,
#[serde(rename = "PS256")]
RsaSsaPssSha256,
#[serde(rename = "PS384")]
RsaSsaPssSha384,
#[serde(rename = "PS512")]
RsaSsaPssSha512,
#[serde(rename = "Ed25519")]
EdDsaEd25519,
#[serde(rename = "none")]
None,
}
impl JwsSigningAlgorithm<CoreJsonWebKeyType> for CoreJwsSigningAlgorithm {
fn key_type(&self) -> Option<CoreJsonWebKeyType> {
match *self {
CoreJwsSigningAlgorithm::HmacSha256
| CoreJwsSigningAlgorithm::HmacSha384
| CoreJwsSigningAlgorithm::HmacSha512 => Some(CoreJsonWebKeyType::Symmetric),
CoreJwsSigningAlgorithm::RsaSsaPkcs1V15Sha256
| CoreJwsSigningAlgorithm::RsaSsaPkcs1V15Sha384
| CoreJwsSigningAlgorithm::RsaSsaPkcs1V15Sha512
| CoreJwsSigningAlgorithm::RsaSsaPssSha256
| CoreJwsSigningAlgorithm::RsaSsaPssSha384
| CoreJwsSigningAlgorithm::RsaSsaPssSha512 => Some(CoreJsonWebKeyType::RSA),
CoreJwsSigningAlgorithm::EcdsaP256Sha256
| CoreJwsSigningAlgorithm::EcdsaP384Sha384
| CoreJwsSigningAlgorithm::EcdsaP521Sha512 => Some(CoreJsonWebKeyType::EllipticCurve),
CoreJwsSigningAlgorithm::EdDsaEd25519 => Some(CoreJsonWebKeyType::OctetKeyPair),
CoreJwsSigningAlgorithm::None => None,
}
}
fn uses_shared_secret(&self) -> bool {
self.key_type()
.map(|kty| kty == CoreJsonWebKeyType::Symmetric)
.unwrap_or(false)
}
fn hash_bytes(&self, bytes: &[u8]) -> Result<Vec<u8>, String> {
use sha2::{Digest, Sha256, Sha384, Sha512};
Ok(match *self {
CoreJwsSigningAlgorithm::HmacSha256
| CoreJwsSigningAlgorithm::RsaSsaPkcs1V15Sha256
| CoreJwsSigningAlgorithm::RsaSsaPssSha256
| CoreJwsSigningAlgorithm::EcdsaP256Sha256 => {
let mut hasher = Sha256::new();
hasher.update(bytes);
hasher.finalize().to_vec()
}
CoreJwsSigningAlgorithm::HmacSha384
| CoreJwsSigningAlgorithm::RsaSsaPkcs1V15Sha384
| CoreJwsSigningAlgorithm::RsaSsaPssSha384
| CoreJwsSigningAlgorithm::EcdsaP384Sha384 => {
let mut hasher = Sha384::new();
hasher.update(bytes);
hasher.finalize().to_vec()
}
CoreJwsSigningAlgorithm::HmacSha512
| CoreJwsSigningAlgorithm::RsaSsaPkcs1V15Sha512
| CoreJwsSigningAlgorithm::RsaSsaPssSha512
| CoreJwsSigningAlgorithm::EcdsaP521Sha512
| CoreJwsSigningAlgorithm::EdDsaEd25519 => {
let mut hasher = Sha512::new();
hasher.update(bytes);
hasher.finalize().to_vec()
}
CoreJwsSigningAlgorithm::None => {
return Err(
"signature algorithm `none` has no corresponding hash algorithm".to_string(),
);
}
})
}
fn rsa_sha_256() -> Self {
CoreJwsSigningAlgorithm::RsaSsaPkcs1V15Sha256
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CoreAuthErrorResponseType {
AccessDenied,
AccountSelectionRequired,
ConsentRequired,
InteractionRequired,
InvalidRequest,
InvalidRequestObject,
InvalidRequestUri,
InvalidScope,
LoginRequired,
RegistrationNotSupported,
RequestNotSupported,
RequestUriNotSupported,
ServerError,
TemporarilyUnavailable,
UnauthorizedClient,
UnsupportedResponseType,
Extension(String),
}
deserialize_from_str!(CoreAuthErrorResponseType);
serialize_as_str!(CoreAuthErrorResponseType);
impl CoreAuthErrorResponseType {
fn from_str(s: &str) -> Self {
match s {
"access_denied" => CoreAuthErrorResponseType::AccessDenied,
"account_selection_required" => CoreAuthErrorResponseType::AccountSelectionRequired,
"consent_required" => CoreAuthErrorResponseType::ConsentRequired,
"interaction_required" => CoreAuthErrorResponseType::InteractionRequired,
"invalid_request" => CoreAuthErrorResponseType::InvalidRequest,
"invalid_request_object" => CoreAuthErrorResponseType::InvalidRequestObject,
"invalid_request_uri" => CoreAuthErrorResponseType::InvalidRequestUri,
"invalid_scope" => CoreAuthErrorResponseType::InvalidScope,
"login_required" => CoreAuthErrorResponseType::LoginRequired,
"registration_not_supported" => CoreAuthErrorResponseType::RegistrationNotSupported,
"request_not_supported" => CoreAuthErrorResponseType::RequestNotSupported,
"request_uri_not_supported" => CoreAuthErrorResponseType::RequestUriNotSupported,
"server_error" => CoreAuthErrorResponseType::ServerError,
"temporarily_unavailable" => CoreAuthErrorResponseType::TemporarilyUnavailable,
"unauthorized_client" => CoreAuthErrorResponseType::UnauthorizedClient,
"unsupported_response_type" => CoreAuthErrorResponseType::UnsupportedResponseType,
ext => CoreAuthErrorResponseType::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreAuthErrorResponseType {
fn as_ref(&self) -> &str {
match *self {
CoreAuthErrorResponseType::AccessDenied => "access_denied",
CoreAuthErrorResponseType::AccountSelectionRequired => "account_selection_required",
CoreAuthErrorResponseType::ConsentRequired => "consent_required",
CoreAuthErrorResponseType::InteractionRequired => "interaction_required",
CoreAuthErrorResponseType::InvalidRequest => "invalid_request",
CoreAuthErrorResponseType::InvalidRequestObject => "invalid_request_obbject",
CoreAuthErrorResponseType::InvalidRequestUri => "invalid_request_uri",
CoreAuthErrorResponseType::InvalidScope => "invalid_scope",
CoreAuthErrorResponseType::LoginRequired => "login_required",
CoreAuthErrorResponseType::RegistrationNotSupported => "registration_not_supported",
CoreAuthErrorResponseType::RequestNotSupported => "request_not_supported",
CoreAuthErrorResponseType::RequestUriNotSupported => "request_uri_not_supported",
CoreAuthErrorResponseType::ServerError => "server_error",
CoreAuthErrorResponseType::TemporarilyUnavailable => "temporarily_unavailable",
CoreAuthErrorResponseType::UnauthorizedClient => "unauthorized_client",
CoreAuthErrorResponseType::UnsupportedResponseType => "unsupported_response_type",
CoreAuthErrorResponseType::Extension(ref ext) => ext.as_str(),
}
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CoreRegisterErrorResponseType {
InvalidClientMetadata,
InvalidRedirectUri,
Extension(String),
}
deserialize_from_str!(CoreRegisterErrorResponseType);
serialize_as_str!(CoreRegisterErrorResponseType);
impl CoreRegisterErrorResponseType {
fn from_str(s: &str) -> Self {
match s {
"invalid_client_metadata" => CoreRegisterErrorResponseType::InvalidClientMetadata,
"invalid_redirect_uri" => CoreRegisterErrorResponseType::InvalidRedirectUri,
ext => CoreRegisterErrorResponseType::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreRegisterErrorResponseType {
fn as_ref(&self) -> &str {
match *self {
CoreRegisterErrorResponseType::InvalidClientMetadata => "invalid_client_metadata",
CoreRegisterErrorResponseType::InvalidRedirectUri => "invalid_redirect_uri",
CoreRegisterErrorResponseType::Extension(ref ext) => ext.as_str(),
}
}
}
impl ErrorResponseType for CoreRegisterErrorResponseType {}
impl RegisterErrorResponseType for CoreRegisterErrorResponseType {}
impl Display for CoreRegisterErrorResponseType {
fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
write!(f, "{}", self.as_ref())
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CoreResponseMode {
Query,
Fragment,
FormPost,
Extension(String),
}
deserialize_from_str!(CoreResponseMode);
serialize_as_str!(CoreResponseMode);
impl CoreResponseMode {
fn from_str(s: &str) -> Self {
match s {
"query" => CoreResponseMode::Query,
"fragment" => CoreResponseMode::Fragment,
"form_post" => CoreResponseMode::FormPost,
ext => CoreResponseMode::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreResponseMode {
fn as_ref(&self) -> &str {
match *self {
CoreResponseMode::Query => "query",
CoreResponseMode::Fragment => "fragment",
CoreResponseMode::FormPost => "form_post",
CoreResponseMode::Extension(ref ext) => ext.as_str(),
}
}
}
impl ResponseMode for CoreResponseMode {}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CoreResponseType {
Code,
IdToken,
None,
Token,
Extension(String),
}
deserialize_from_str!(CoreResponseType);
serialize_as_str!(CoreResponseType);
impl CoreResponseType {
fn from_str(s: &str) -> Self {
match s {
"code" => CoreResponseType::Code,
"id_token" => CoreResponseType::IdToken,
"none" => CoreResponseType::None,
"token" => CoreResponseType::Token,
ext => CoreResponseType::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreResponseType {
fn as_ref(&self) -> &str {
match *self {
CoreResponseType::Code => "code",
CoreResponseType::IdToken => "id_token",
CoreResponseType::None => "none",
CoreResponseType::Token => "token",
CoreResponseType::Extension(ref ext) => ext.as_str(),
}
}
}
impl ResponseType for CoreResponseType {
fn to_oauth2(&self) -> OAuth2ResponseType {
OAuth2ResponseType::new(self.as_ref().to_string())
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CoreSubjectIdentifierType {
Pairwise,
Public,
Extension(String),
}
deserialize_from_str!(CoreSubjectIdentifierType);
serialize_as_str!(CoreSubjectIdentifierType);
impl CoreSubjectIdentifierType {
fn from_str(s: &str) -> Self {
match s {
"pairwise" => CoreSubjectIdentifierType::Pairwise,
"public" => CoreSubjectIdentifierType::Public,
ext => CoreSubjectIdentifierType::Extension(ext.to_string()),
}
}
}
impl AsRef<str> for CoreSubjectIdentifierType {
fn as_ref(&self) -> &str {
match *self {
CoreSubjectIdentifierType::Pairwise => "pairwise",
CoreSubjectIdentifierType::Public => "public",
CoreSubjectIdentifierType::Extension(ref ext) => ext.as_str(),
}
}
}
impl SubjectIdentifierType for CoreSubjectIdentifierType {}
pub(crate) fn base64_url_safe_no_pad() -> base64::Config {
base64::URL_SAFE_NO_PAD.decode_allow_trailing_bits(true)
}
#[cfg(test)]
mod tests;