public void SimpleAuthenticatedRequest() { client = new JsonServiceClient (serverUrl); var oauth = new OAuthConnection (serverUrl); var access_token = TokenExchange (); client.LocalHttpWebRequestFilter += webservice_request => { var auth_header = OAuthConnection.GenerateAuthorizationHeader (access_token, webservice_request.RequestUri, RequestMethod.GET, ""); webservice_request.Headers ["Authorization"] = auth_header; }; var resp = client.Get<UserResponse> (serverUrl + "/api/1.0/" + testUser); }
public static IOAuthToken PerformTokenExchange(string serverUrl, string oauthCallbackUrl, OAuthAuthorizationCallback callback) { var oauth_connection = new OAuthConnection (serverUrl); string link_to_open_for_user = ""; link_to_open_for_user = oauth_connection.GetAuthorizationUrl (oauthCallbackUrl); string verifier = callback (link_to_open_for_user); bool result = oauth_connection.GetAccessAfterAuthorization (verifier); if (result == false) throw new UnauthorizedAccessException (); var token = oauth_connection.AccessToken; return token; }
public static string GenerateAuthorizationHeader(IOAuthToken accessToken, Uri uri, RequestMethod method, string postData) { var oauth = new OAuthConnection (uri.ToString()); oauth.AccessToken = accessToken; return oauth.GenerateAuthorizationHeader (uri, method, postData); }