Simple in theory. Assuming you are mounting the beam to the side of the post at the top. You have an ideal situation for a cantilever. It even follows the old rule of 1/3 (cantilever), 2/3 (back span).
To size it, find any floor joist chart and figure the span of 8'. A 2x8 spans upward of 12'.
Load wise you will probably never hit over 200-300 lb on the rope swing so a couple 3/8"-1/2" through bolts at each post through the beam would be overkill. With those loads, even 6-8 long screws would be more than enough (@ aprox 70-100lb+ per screw).
Biggest problem will be rot between the beam and the post over time as water gets trapped between the two. For this we usually use the through bolts and put a small stack of galvanized washers (5-10) between the post and the beam.
As for bracing it laterally, using a wider member like a 4x would help. So a 4x8 would probably be ideal, and a 4x6 should work well enough. But then you need through bolts for sure.