Index: protocols/twitter/twitter.c
===================================================================
--- protocols/twitter/twitter.c	(revision a7c6d0e9a9d985534dc18d450399d6a7ece6c592)
+++ protocols/twitter/twitter.c	(revision c2ecadc08daa5163f4c90aef36de0e33d0d44f16)
@@ -28,5 +28,4 @@
 #include "twitter_lib.h"
 
-
 /**
  * Main loop function
@@ -66,4 +65,14 @@
 }
 
+
+static struct oauth_service twitter_oauth =
+{
+	"http://api.twitter.com/oauth/request_token",
+	"http://api.twitter.com/oauth/access_token",
+	"http://api.twitter.com/oauth/authorize",
+	.consumer_key = "xsDNKJuNZYkZyMcu914uEA",
+	.consumer_secret = "FCxqcr0pXKzsF9ajmP57S3VQ8V6Drk4o2QYtqMcOszo",
+};
+
 static gboolean twitter_oauth_callback( struct oauth_info *info );
 
@@ -74,6 +83,5 @@
 	imcb_log( ic, "Requesting OAuth request token" );
 
-	td->oauth_info = oauth_request_token(
-		TWITTER_OAUTH_REQUEST_TOKEN, twitter_oauth_callback, ic );
+	td->oauth_info = oauth_request_token( &twitter_oauth, twitter_oauth_callback, ic );
 }
 
@@ -100,6 +108,6 @@
 		sprintf( name, "twitter_%s", ic->acc->user );
 		msg = g_strdup_printf( "To finish OAuth authentication, please visit "
-		                       "%s?%s and respond with the resulting PIN code.",
-		                       TWITTER_OAUTH_AUTHORIZE, info->auth_params );
+		                       "%s and respond with the resulting PIN code.",
+		                       info->auth_url );
 		imcb_buddy_msg( ic, name, msg, 0, 0 );
 		g_free( msg );
@@ -107,5 +115,5 @@
 	else if( info->stage == OAUTH_ACCESS_TOKEN )
 	{
-		if( info->access_token == NULL )
+		if( info->token == NULL )
 		{
 			imcb_error( ic, "OAuth error: %s", info->http->status_string );
@@ -114,10 +122,8 @@
 		}
 		
-		td->oauth = g_strdup( info->access_token );
-		
 		/* IM mods didn't do this so far and it's ugly but I should
 		   be able to get away with it... */
-		g_free( ic->acc->pass );
-		ic->acc->pass = g_strdup( info->access_token );
+		//g_free( ic->acc->pass );
+		//ic->acc->pass = g_strdup( info->access_token );
 		
 		twitter_main_loop_start( ic );
@@ -126,4 +132,5 @@
 	return TRUE;
 }
+
 
 static char *set_eval_mode( set_t *set, char *value )
@@ -164,6 +171,6 @@
 	if( !set_getbool( &acc->set, "oauth" ) )
 		td->pass = g_strdup( acc->pass );
-	else if( strstr( acc->pass, "oauth_token=" ) )
-		td->oauth = g_strdup( acc->pass );
+	//else if( strstr( acc->pass, "oauth_token=" ) )
+	//	td->oauth = g_strdup( acc->pass );
 	td->home_timeline_id = 0;
 	
@@ -172,5 +179,5 @@
 	imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL );
 	
-	if( td->pass || td->oauth )
+	if( td->pass || td->oauth_info )
 		twitter_main_loop_start( ic );
 	else
@@ -197,7 +204,5 @@
 	{
 		oauth_info_free( td->oauth_info );
-		
 		g_free( td->pass );
-		g_free( td->oauth );
 		g_free( td );
 	}
@@ -216,8 +221,13 @@
 	    g_strcasecmp(who + 8, ic->acc->user) == 0)
 	{
-		if( set_getbool( &ic->acc->set, "oauth" ) && td->oauth_info )
+		if( set_getbool( &ic->acc->set, "oauth" ) &&
+		    td->oauth_info && td->oauth_info->token == NULL )
 		{
-			oauth_access_token( TWITTER_OAUTH_ACCESS_TOKEN, message, td->oauth_info );
-			td->oauth_info = NULL;
+			if( !oauth_access_token( message, td->oauth_info ) )
+			{
+				imcb_error( ic, "OAuth error: %s", "Failed to send access token request" );
+				imc_logout( ic, TRUE );
+				return FALSE;
+			}
 		}
 		else
Index: protocols/twitter/twitter.h
===================================================================
--- protocols/twitter/twitter.h	(revision a7c6d0e9a9d985534dc18d450399d6a7ece6c592)
+++ protocols/twitter/twitter.h	(revision c2ecadc08daa5163f4c90aef36de0e33d0d44f16)
@@ -37,5 +37,4 @@
 	char* user;
 	char* pass;
-	char* oauth;
 	struct oauth_info *oauth_info;
 	guint64 home_timeline_id;
@@ -52,7 +51,3 @@
 GSList *twitter_connections;
 
-#define TWITTER_OAUTH_REQUEST_TOKEN "http://api.twitter.com/oauth/request_token"
-#define TWITTER_OAUTH_ACCESS_TOKEN  "http://api.twitter.com/oauth/access_token"
-#define TWITTER_OAUTH_AUTHORIZE     "http://api.twitter.com/oauth/authorize"
-
 #endif //_TWITTER_H
Index: protocols/twitter/twitter_http.c
===================================================================
--- protocols/twitter/twitter_http.c	(revision a7c6d0e9a9d985534dc18d450399d6a7ece6c592)
+++ protocols/twitter/twitter_http.c	(revision c2ecadc08daa5163f4c90aef36de0e33d0d44f16)
@@ -29,5 +29,4 @@
 ****************************************************************************/ 
 
-#include "twitter_http.h"
 #include "twitter.h"
 #include "bitlbee.h"
@@ -39,4 +38,6 @@
 #include <errno.h>
 
+#include "twitter_http.h"
+
 
 char *twitter_url_append(char *url, char *key, char* value);
@@ -46,5 +47,5 @@
  * This is actually pretty generic function... Perhaps it should move to the lib/http_client.c
  */
-void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, char* user, char* pass, char* oauth_token, char** arguments, int arguments_len)
+void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, char* user, char* pass, struct oauth_info* oi, char** arguments, int arguments_len)
 {
 	url_t *url = g_new0( url_t, 1 );
@@ -111,10 +112,9 @@
 
 	// If a pass and user are given we append them to the request.
-	if (oauth_token)
+	if (oi)
 	{
 		char *full_header;
 		
-		full_header = oauth_http_header(oauth_token,
-		                                is_post ? "POST" : "GET",
+		full_header = oauth_http_header(oi, is_post ? "POST" : "GET",
 		                                url_string, url_arguments);
 		
Index: protocols/twitter/twitter_http.h
===================================================================
--- protocols/twitter/twitter_http.h	(revision a7c6d0e9a9d985534dc18d450399d6a7ece6c592)
+++ protocols/twitter/twitter_http.h	(revision c2ecadc08daa5163f4c90aef36de0e33d0d44f16)
@@ -28,6 +28,8 @@
 #include "http_client.h"
 
+struct oauth_info;
+
 void *twitter_http(char *url_string, http_input_function func, gpointer data, int is_post, 
-                   char* user, char* pass, char *oauth_token, char** arguments, int arguments_len);
+                   char* user, char* pass, struct oauth_info *oi, char** arguments, int arguments_len);
 
 #endif //_TWITTER_HTTP_H
Index: protocols/twitter/twitter_lib.c
===================================================================
--- protocols/twitter/twitter_lib.c	(revision a7c6d0e9a9d985534dc18d450399d6a7ece6c592)
+++ protocols/twitter/twitter_lib.c	(revision c2ecadc08daa5163f4c90aef36de0e33d0d44f16)
@@ -130,5 +130,5 @@
 	args[0] = "cursor";
 	args[1] = g_strdup_printf ("%d", next_cursor);
-	twitter_http(TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, td->oauth, args, 2);
+	twitter_http(TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, td->user, td->pass, td->oauth_info, args, 2);
 
 	g_free(args[1]);
@@ -396,5 +396,5 @@
 	}
 
-	twitter_http(TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, td->user, td->pass, td->oauth, args, td->home_timeline_id ? 4 : 2);
+	twitter_http(TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, td->user, td->pass, td->oauth_info, args, td->home_timeline_id ? 4 : 2);
 
 	g_free(args[1]);
@@ -510,5 +510,5 @@
 	{
 		td->http_fails = 0;
-		if (!ic->flags & OPT_LOGGED_IN)
+		if (!(ic->flags & OPT_LOGGED_IN))
 			imcb_connected(ic);
 	}
@@ -620,5 +620,5 @@
 	args[1] = g_strdup_printf ("%d", next_cursor);
 
-	twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, td->oauth, args, 2);
+	twitter_http(TWITTER_SHOW_FRIENDS_URL, twitter_http_get_statuses_friends, ic, 0, td->user, td->pass, td->oauth_info, args, 2);
 
 	g_free(args[1]);
@@ -654,5 +654,5 @@
 	args[0] = "status";
 	args[1] = msg;
-	twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth, args, 2);
+	twitter_http(TWITTER_STATUS_UPDATE_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth_info, args, 2);
 //	g_free(args[1]);
 }
@@ -672,5 +672,5 @@
 	args[3] = msg;
 	// Use the same callback as for twitter_post_status, since it does basically the same.
-	twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth, args, 4);
+	twitter_http(TWITTER_DIRECT_MESSAGES_NEW_URL, twitter_http_post_status, ic, 1, td->user, td->pass, td->oauth_info, args, 4);
 //	g_free(args[1]);
 //	g_free(args[3]);
