I've been asked by a colleague to write a post about coauthorship. This topic comes up often in courses on scientific ethics and responsible conduct of research. Like many of these things, my sense is that good practice prevails in the large majority of circumstances, though not 100% of the time. I think my views on this are in line with the mainstream, at least in condensed matter physics. First, to be a coauthor, a person has to have made a real intellectual contribution to the work, somewhere in the planning, execution, analysis, and/or writeup stages. Simply paying for a person's time, some supplies, or lending a left-handed widget does not alone entitle someone to coauthorship. It's best to have straightforward, direct conversations with potential coauthors early on, before the paper is written, to make sure that they understand this. A couple of times I've turned down offers of coauthorship b/c I felt like I didn't really contribute to the paper; once, for example, one of my students did some lithography for a colleague as a favor, while offering advice on sample design. She rightfully was a coauthor, but I hadn't really done anything beyond say that this was fine with me.
The challenge is, the current culture of h indices and citation metrics rewards coauthorship. People coming out of large research groups with many-person collaborative projects can end up looking fantastic in some of these metrics, a bias exacerbated if coauthorships are distributed lightly. Research cultures that have very hierarchical structures can also lead to "courtesy" coauthorships (Does the Big Professor or Group Leader who runs a whole institute or laboratory automatically end up on all the important papers that come out of there, even if they are extremely detached from the work? I hope not.).
Coauthorship entails responsibilities, and this is where things can get ethically tricky. As a coauthor, minimally you should contribute to the writing of the manuscript (even if that means reading a draft and offering substantive comments) and actually understand the research. Just understanding your own little piece and having no clue about the rest is not acceptable. At the same time, it's not really fair to expect, e.g., the MBE materials grower to know in detail some low-T, rf experimental technique tidbit, but s/he should at least understand the concepts. A coauthor should know enough to ask salient questions during the analysis and writeup.
Note that all of this gets rather murky when dealing with very large, collaborative projects (e.g., particle physics). When CERN collaborations produce a paper with 850 coauthors, do I think that each of them really read the manuscript in detail? No, but they have a representative system with internal committees, etc. for internal review and deciding authorship, and the ones I talk to are aware of the challenges that this represents.
Some topics lend themselves more to a back-an-forth in the comments, and this may be one. I'm happy to try to answer questions on this.