Is it safe to oil a lock?
No. You're likley to gum up the works. Graphite is common but not actually recommended. Not knowing the brand of your lock, I went and looked up one of the best-regarded lock makers (Medeco) and they recommend 3 products, two of which are not their house-branded product:

Medeco KeyLube 2.0 Multi-purpose Lubricant PX-KYLUB2-03 (5.25 oz.) Aerosol can with spray tube

Sandstrom Poxylube CP-200 Air Drying Solid Film Lubricant Poxylube CP-200 (4.5 oz.) Aerosol can with spray tube

Synco Super Lube Dri-Film Lubricant
Super Lube Dri-Film (11 oz.) Aerosol can with spray tube

This existing DIY StackExchange question which will probably mean yours is closed as a duplicate has another suggestion LAB Locksmith Lube, (and another diss on graphite) by another respected lock maker, Yale:

What Should I use to Lubricate a Lock?

Looks like the best consensus (there is a lot of conflicting information in that thread alone) is probably a dry-film spray-teflon product, these days.