public string CreateAndSignAccessToken(string oauth_token) { var accessToken = FluentTwitter.CreateRequest() .Authentication.GetAccessToken(OAuth.GetOAuthSecrets().Key, OAuth.GetOAuthSecrets().Secret, oauth_token); var response = accessToken.Request(); var result = response.AsToken(); if (result == null) { var error = response.AsError(); if (error != null) { throw new Exception(error.ErrorMessage); } throw new Exception(); } if (result.Token != null && result.TokenSecret != null && result.ScreenName != null) { return(SignedString.CreateSignedString(Encryptor.EncryptString(SerializeToken(result), EncryptingKey), SigningKey)); } else { return(null); } }
public OAuthToken GetTokenFromCooke(HttpCookie cookie) { if (cookie == null) { return(null); } if (cookie.Value == null) { return(null); } try { var serialized = Encryptor.DescryptString( SignedString.ExtractAndVerifyMessage(cookie.Value, SigningKey), EncryptingKey); return(DeserializeToken(serialized)); } catch (CryptographicException) { //a cryptographic exception could be thrown if we changed keys... //beware though, this can disguise bad crypto code too return(null); } catch (InvalidSignatureExecption) { return(null); } }