We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

Tenant status change notifications

In this article

    While there are several ways to accomplish processing tenant status changes notification, the following is a short description of what that might look using .NET and C#.

    CustomerStateChangeNotificationType Enumeration

    public enum CustomerStateChangeNotificationType
    {
        Upgrade = 0,
        BackupRestored = 1,
        Suspend = 2,
        Resume = 3,
        Delete = 4
    }

    Notification Message

    public class NotificationMessage 
    { 
        public CustomerStateChangeNotificationType ChangeType { get; set; } 
        public string ContextIdentifier { get; set; } 
        public string VersionName { get; set; } 
        public string FileVersion { get; set; } 
        public string Token { get; set; } 
    } 

     

    API Controller and JWT Validation

    public class NotifyCustomerStateChangeController : ApiController 
    { 
        public void Post([FromBody]NotificationMessage message) 
        { 
           try
           {
               // SuperIdTokenHandler is available in 
               // nuget package: SuperOffice.Crm.Online.Core
    
               SuperIdToken validated = ValidateToken(message.Token);
    
               // process accordingly...
               
    
           }
           catch (Exception ex)
           {
               // handle invalid token...
               throw;
           }
        } 
    
        public static SuperIdToken ValidateToken(string token)
        {
            var path = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/") + "SOD_SuperOfficeFederatedLogin.crt";
    
            var tokenHandler = new SuperIdTokenHandler();
            tokenHandler.JwtIssuerSigningCertificate = new X509Certificate2(path);
            tokenHandler.CertificateValidator = X509CertificateValidator.ChainTrust;
            tokenHandler.ValidIssuer = "https://sod.superoffice.com";
            
            return tokenHandler.ValidateToken(token, TokenType.Jwt);
        }
    }