LazyStack

AuthProcessMessages.json

The LazyStackAuth project contains an embedded resource file AuthMessages.json. This file contains message text, by language, for relevant AuthProcess states and events. Note that the key for the language, in this case "en-US", a combination of an ISO 639 two-letter lowercase culture code associated with a language and an ISO 3166 two-letter uppercase subculture code associated with a country or region. You can find a nice list for many valid keys here.

{
    "AuthProcessLabels": {
      "en-US": {
        "None": "",
        "SigningIn": "Sign In",
        "SigningUp": "Sign Up",
        "ResettingPassword": "Reset Password",
        "UpdatingLogin": "Update Login",
        "UpdatingEmail": "Update Email",
        "UpdatingPhone": "Update Phone",
        "UpdatingPassword": "Update Password",
        "SigningOut": "Sign Out"
      }
    },
    "AuthFormatMessages": {
      "en-US": {
        "Login01": "Login length must be at least 8 characters long.",
        "Password01": "Password must contain at least one capital letter.",
        "Password02": "Password must contain at least one lowercase letter.",
        "Password03": "Password must contain at least one digit.",
        "Password04": "Password length must be at least 8 characters long.",
        "Email01": "Enter a valid email address.",
        "Code01":  "Code must be six digits.",
        "Phone01":  "Invalid phone number."
      }
    },
    "AuthProcessMessages": {
      "en-US": {
        "None": "",
        "SigningIn": "Signing In",
        "SigningUp": "Signing Up",
        "ResettingPassword": "Resetting Password",
        "UpdatingLogin": "Updating Login",
        "UpdatingEmail": "Updating Email",
        "UpdatingPhone": "Updating Phone",
        "UpdatingPassword": "Updating Password",
        "SigningOut": "Signing Out"
      }
    },
    "AuthChallengeMessages": {
      "en-US": {
        "None": "",
        "Login": "Enter your Login",
        "NewLogin": "Enter new Login",
        "Password": "Enter your Password",
        "NewPassword": "Enter a new Password",
        "Email": "Enter your Email address",
        "NewEmail": "Enter your new Email address",
        "Phone": "Enter your mobile phone number",
        "NewPhone": "Enter you new mobile phone number",
        "Code": "Enter authentication code"
      }
    },
    "AuthAlertMessages": {
      "en-US": {
        "Alert_AuthProcessAlreadyStarted": "Another Authentication Process is already started.",
        "Alert_DifferentAuthProcessActive": "Different Authentication Process is active.",
        "Alert_IncorrectAuthProcess": "Invalid call for currently active Authentication Process.",
        "Alert_NoActiveAuthProcess": "No Authentication Process is active.",
        "Alert_AlreadySignedIn": "You are already Signed In.",
        "Alert_InternalSignInError": "Internal Sign In Error.",
        "Alert_InternalSignUpError": "Internal Sign Up Error.",
        "Alert_InternalProcessError": "Internal Authentication Process Error.",
        "Alert_SignUpMissingLogin": "Attempt to Sign Up with no Login value.",
        "Alert_SignUpMissingPassword": "Attempt to Sign UP with no Password value.",
        "Alert_SignUpMissingEmail": "Attempt to Sign Up with no Email value.",
        "Alert_SignUpMissingCode": "Attempt to Sign Up with no Code value.",
        "Alert_AuthAlreadyStarted": "Authentication is already started.",
        "Alert_InvalidCallToResendAsyncCode": "Invalid request to resend authentication code.",
        "Alert_AccountWithThatEmailAlreadyExists": "Another account with that email already exists.",
        "Alert_RefreshUserDetailsDone": "Refresh of user details completed.",
        "Alert_EmailAddressIsTheSame": "New email address is the same as currently registered email address.",
        "Alert_VerifyCalledButNoChallengeFound": "A verify challenge was called but no current challenge was found.",
        "Alert_CantRetrieveUserDetails": "Can't retrieve user details.",
        "Alert_NeedToBeSignedIn": "You need to be signed in to perform the requested operation.",
        "Alert_InvalidOperationWhenSignedIn": "You need to be signed out to perform the requested operation.",
        "Alert_UserNotFound": "User Login not found.",
        "Alert_NotConfirmed": "User credentials can not be confirmed.",
        "Alert_NotAuthorized": "User is not authorized.",
        "Alert_VerifyFailed": "User verification failed.",
        "Alert_LoginAlreadyUsed": "Sorry, that user login is already used. Please choose another.",
        "Alert_LoginMustBeSuppliedFirst": "Login must be supplied first.",
        "Alert_LoginFormatRequirementsFailed": "Login format requirements not satisfied.",
        "Alert_PasswordFormatRequirementsFailed": "Password format requirements not satisfied.",
        "Alert_EmailFormatRequirementsFailed": "The supplied Email is not valid.",
        "Alert_PhoneFormatRequirementsFailed": "The supplied Phone is not valid.",
        "Alert_TooManyAttempts": "You have exceeded the login attempt limit. Try again later.",
        "Alert_NothingToDo": "",
        "Alert_OperationNotSupportedByAuthProvider": "Operation not supported by current auth provider.",
        "Alert_LimitExceededException": "Too many attempts. Try again later.",
        "Alert_PasswordResetRequiredException":  "Password must be reset.",
        "Alert_Unknown": "Unknown Alert Raised."
      }
    },
    "AuthLabels": {
      "en-US": {
        "LoginLabel": "Login",
        "NewLoginLabel": "New Login",
        "PasswordLabel": "Password",
        "NewPasswordLabel": "New Password",
        "EmailLabel": "Email",
        "NewEmailLabel": "New Email",
        "PhoneLabel": "Phone",
        "NewPhoneLabel": "New Phone",
        "CodeLabel": "Code"
      }
    }
  }
IConfiguration

LazyStackAuth uses the .Net ConfigurationBuilder to store configuration information like that provided in AuthMessages.json. Since the default AuthMessages.json is an embedded resource you may read it into Configuration builder like this:

...
    using var authMessagesStream = typeof(IAuthProcess).Assembly.GetManifestResourceStream("LazyStackAuth.AuthMessages.json");
    using var awsSettingsStream = typeof(Program).Assembly.GetManifestResourceStream("PetStoreConsoleApp.AwsSettings.json");
    IConfiguration appConfig = new ConfigurationBuilder()
    .AddJsonStream(authMessageStream)
    .AddJsonStream(awsSettingsStream)
    .Build();
    var authProvider = new AuthProviderCognito(appConfig); // Implements IAuthProvider interface for AWS Cognito
    var authProcess = new AuthProcess(appConfig, authProvider); // Implements IAuthProcess interface
...

Note that the configuration referenced in appConfig is passed to the AuthProcess(appConfig, authProvider) constructor. This gives the AuthProcess access to the AuthMessages.

In addition to reading the embedded AuthMessages.json file, the code above also loads the embedded AwsSettings.json file. We discuss this file in detail later but for now you should understand that the AwsSettings.json file contains the configuration information necessary for your client application to connect to and call your AWS application stack. LazyStack generates the AwsSettings.json file for you.

You may extend/override the AuthMessages by reading your own JSON document. If you introduce support for a new language you tell LazyStackAuth to use that new language by setting the AuthProcess.LanguageCode property. For example, let's say you introduced support for Spanish as spoken in Mexico by creating your own local embedded resource file MoreAuthMessages.json - the language code would be "ex-MX" and your C# code might look something like this:

...
    using var authMessagesStream = typeof(IAuthProcess).Assembly.GetManifestResourceStream("LazyStackAuth.AuthMessages.json");
    using var moreAuthMessagesStream = typeof(Program).Assembly.GetManifestResourceStream("PetStoreConsoleApp.MoreAuthMessages.json");
    using var awsSettingsStream = typeof(Program).Assembly.GetManifestResourceStream("PetStoreConsoleApp.AwsSettings.json");
    IConfiguration appConfig = new ConfigurationBuilder()
    .AddJsonStream(authMessagesStream)
    .AddJsonString(moreAuthMessagesStream)
    .AddJsonStream(awsSettingsStream)
    .Build();
    var authProvider = new AuthProviderCognito( // Implements IAuthProvider interface for AWS Cognito
        appConfig,
        loginFormat: new LoginFormat(appConfig), // Class checks format of login
        passwordFormat: new PasswordFormat(appConfig), // Class checks format of password
        emailFormat: new EmailFormat(appConfig), // Class checks email format
        codeFormat: new CodeFormat(appConfig), // Class checks confirmation code format
        phoneFormat: new PhoneFormat(appConfig); // Class checks phone number format
        ); 
    var authProcess = new AuthProcess(appConfig, authProvider); // Implements IAuthProcess interface
    authProcess.LanguageCode ="ex-MX";
...