As a manager, here's some simple rules for when to give and take credit for things:
Rule 1: When things are going well: give all the credit to others. This includes members of your team and others external but involved with the team (sometimes even competitors).
Rule 2: When things aren't going well: take all the blame. Then take action to fix it.
Too often I see scenarios where the giving and taking of credit for good ideas or jobs well done is carefully bartered and feelings get hurt easily. The idea of a manager taking credit for the work of those he manages is so often cited it's now cliché. It's jut a given in some places. We should strive to not be like that. Doing so creates resentment, undermines work performance, and damages your credibility.
If you find yourself in a scenario where somebody else has taken credit for your work, I've found it's always best to forgive unconditionally. Yes, I said always. Harbouring your own resentment will undermine your own work performance and create barriers to your ability to communicate; never good. If it's unjust enough that you get actually angry about it, just relax. Take some time off or go work on something else until you cool down. Then get over it and get back to work as if it never happened. This is how to handle something with grace.
I've used the word grace in a few blog posts. I looked up the definition today. A funny thing about it, I think that when you give a pardon with grace you're acknowledging that the forgiveness isn't deserved. They did something wrong and you're consciously making the decision to forget about it. This is grace.
As I read modern thinking about scenarios like this, the universal advice seems to be to confront the offender. I think this is a terrible idea and here's why: they know they did it and they already feel guilty about it. If they don't know they did it, then they were acting without malicious intent so it doesn't matter anyway. Why people do something is more important than what they do. The universal sense of what's right and wrong is written into the heart of every person. It's why we want to seek justice in the first place, because we want to make the other person suffer more in their guilt. I don't think that's ever the right thing to do. Better to drop it, move on, and keep trying to live and work as a better example. Folks will see that. With enough exposure to it, they will eventually want to emulate it.