While your question is easy, the answer is actually quite complex. Statutorily, there is no legislation that requires an officer to disclose their full identity to you. However, as others have consistently stated already, most officers are bound by the polices/rules of their individual police services. If they contravene that, they can be brought up on charges under the Police Services Act.
What complicates the issue is where someone tries to make an Access to Information request. There is quite a bit of case law in this area but the 2 most cited decisions are Metropolitan Toronto Police Services Board (Re) (an appeal decision) and more importantly, the Division Court's decision in Duncanson v. Fineberg. I think most will agree that disclosing the names of officers can put them and their loved ones in peril, as well as significantly impede their ability to do undercover work.
However, if you read paragraph 254, you'll see that even the TPS agrees that there are times in specific cases where such disclosure is necessary.
So, that's the general police requirements.
However, from a practical perspective, if the accused can raise issue that he/she did not know the person was an officer, than it challenges virtually all the evidence of the Crown. After all, if any 'demand' is made by an officer, the accused must have a reasonable basis to know that such demand is truly coming from an 'agent of the Crown'. That is why the police policies are in place and why officers are issued badges/shields. This way, the Crown can argue that the defendant should have known the person was an agent of the Crown because he was wearing a uniform, was in a marked vehicle, was displaying their badge, etc. In other words, they will argue all those items to establish that a reasonable person WOULD have known the demand, detention and/or arrest were truly coming from an 'agent of the Crown'.
So, that's the complicated answer. In short, officers must abide by their police service's rules of identifying themselves. Practically speaking though, they WILL provide their name and badge number so that their testimony/evidence is better accepted in court and survive defense lawyer attacks.