示例#1
0
        private int GetPartnerIdFromSessionId(string sessionId)
        {
            if (String.IsNullOrEmpty(sessionId))
            {
                throw new FormatException("SessionId can not be empty");
            }

            string formatedSessionId = sessionId.Replace('-', '+');

            string[] splittedSessionId = OpenTokUtils.SplitString(formatedSessionId, '_', 2);
            if (splittedSessionId == null)
            {
                throw new FormatException("Session id could not be decoded");
            }

            string decodedSessionId = OpenTokUtils.Decode64(splittedSessionId[1]);

            string[] sessionParameters = OpenTokUtils.SplitString(decodedSessionId, '~', 0);
            if (sessionParameters == null)
            {
                throw new FormatException("Session id could not be decoded");
            }

            return(Convert.ToInt32(sessionParameters[1]));
        }
示例#2
0
        private Dictionary <string, string> CheckToken(string token, int apiKey)
        {
            string baseToken = OpenTokUtils.Decode64(token.Substring(4));

            char[]   sep         = { '&' };
            string[] tokenFields = baseToken.Split(sep);
            var      tokenData   = new Dictionary <string, string>();

            for (int i = 0; i < tokenFields.Length; i++)
            {
                tokenData.Add(tokenFields[i].Split('=')[0], tokenFields[i].Split('=')[1]);
            }
            return(tokenData);
        }
示例#3
0
        private void CheckToken(string token, int apiKey)
        {
            string       baseToken = OpenTokUtils.Decode64(token.Substring(4));
            const string partnerId = "partner_id=";
            const string sig       = "sig=";


            char[]   sep         = { '&' };
            string[] tokenFields = baseToken.Split(sep);

            Assert.True(tokenFields[0].StartsWith(partnerId));
            Assert.True(tokenFields[1].StartsWith(sig));
            Assert.Equal(Convert.ToInt32(tokenFields[0].Substring(partnerId.Length)), apiKey);
        }