// From a Base64 encoded string, extract the values for a token public static OSAuthToken FromString(string pTokenString) { OSAuthToken token; try { string jToken = Encoding.UTF8.GetString(System.Convert.FromBase64String(pTokenString)); token = new OSAuthToken(); if (jToken.TrimStart().StartsWith("{")) { JObject jObj = JObject.Parse(jToken); foreach (KeyValuePair <string, JToken> val in jObj) { token.AddProperty(val.Key, (string)val.Value); } } else { // The token doesn't look like JSON so assume it's a random string token = new OSAuthToken { _randomString = pTokenString }; } } catch { // Most likely here because the parsing of the token failed. // This means the string was just a token by itself token = new OSAuthToken { _randomString = pTokenString }; } return(token); }
// Validate the passed authorization string. // The string is presumed to be a JWT string so check the signature and expiration of same. public bool Validate(string pAuthString, OSAuthToken pToken) { bool ret = false; if (pToken == null) { // If there is no connection client token yet, verify that the // auth string is a legal JWT // TODO: ret = true; } else { ret = (pAuthString == pToken.Token); } _log.DebugFormat("{0} Validate: {1}. Auth={2}", _logHeader, pAuthString, ret); return(ret); }
public bool Validate(OSAuthToken pToken) { _log.DebugFormat("{0} Validate just token. Auth={1}", _logHeader, true); return(true); }
public bool Matches(string pOther) { OSAuthToken otherT = OSAuthToken.FromString(pOther); return(Matches(otherT)); }
// Check that the significant pieces of this token matches the passed token public bool Matches(OSAuthToken pOther) { return((this.Sid == pOther.Sid) && (this.Secret == pOther.Secret)); }