A, B — my current bosses. X — my ex-boss.
A — I've spent a semester on sabbatical at the institution of X. Here is some data I produce. You have to write 2 papers.
Me (after 3 month, working completely independent; I am on the stage of the scientific career that does not need any supervision) — Here is your paper (it will be probably submitted to a top journal).
B — Very good, only 2 corrections. Add this to the acknowledgements and X to the authors list.
Me — X contributed nothing to the work. Besides, (s)he has already taken advantage of my dfg project and made everything possible that (s)he becomes the formal supervisor of the phd student funded by my project (see this post). Why should I add (her)him?
B — I need a paper with (her)him so that (s)he writes me a reference letter, don't you know I am looking for a prof. position.
A — You have to add X to the list of authors, haven't I told you that I spent a semester there. Besides, it is good for B's career.
With uneasy mind I have done what I am told to do. My health is more precious to me... However, I am recurrently coming back to this issue. Have I done everything right?
Comments in response to questions (edited)
Thank you all for very active participation and numerous questions. Unfortunately, I cannot provide more information as requested. The question can be closed as unclear, however, I do not want to reveal my identity.