private string GetClientId() { if (_queryParams != null && _queryParams.ContainsKey("clientId") && !string.IsNullOrEmpty(_queryParams?["clientId"])) { return(_queryParams["clientId"]); } else { var contextTokenParts = ContextToken?.Split('.'); if (contextTokenParts != null && contextTokenParts.Length > 1) { var mainPart = contextTokenParts[1]; try { var jwt = TokenHelper.Base64DecodeJwtToken(mainPart); var deserializer = new JavaScriptSerializer(); var tokenProperties = deserializer.Deserialize <Dictionary <string, string> >(jwt); if (tokenProperties.ContainsKey("aud")) { return(tokenProperties["aud"].Split('/')[0]); } } catch { // ignored } } } return(null); }