Where were you when I needed you?
I used the phrase
Where are you when I needed you?
Is the grammar correct? I don't know if it is.
No. The first statement is right and the second is wrong.
When you say "when I needed you," you are referring to the past. You intend to know where the person was at that time. So the statement
"Where were you when I needed you?"
is grammatically correct.
The question "Where are you?" is at the present tense, so there is a conflict of tenses when you state
"Where are you, when I needed you?"
which doesn't make grammatical sense.