Using Azure AD authentication for a Go API
So after a long time I thought I’d take another look at Go and whilst struggling to think what little app should I write to get back in the saddle with, the legend that is Christos Matskas mentioned he wanted to try using a Go api against Azure AD for authentication. So I fired up GoLand and got to work writing an API.
Setting up Azure AD You will need to create an Azure Directory in your account which is pretty straightforward. The only user in the directory will be you. Inside the directory you will then need to register an application, again pretty straightforward. Next under Certificates & Secrets, you will need to create a secret, this will be used as part of the auth handshake. Give it a name and Azure will create the value. Take a copy of it ready for your API On the Overview page take a copy of the Application (client) ID On the Overview page take a copy of the Directory (tenant) ID Go to Expose An API Click Add a scope Create something like “allow_user” and choose Admins and users Go to API Permissions and click Add a Permission Select My APIs and select your application/API Tick the scope you just created Now here’s a weird thing, if you don’t see your scope, try going to another tab in your browser or refresh you Azure Portal page. Something is broken IMO in that it takes time or needs refreshing for it to show up Click Manifest on the left hand side Change accessTokenAcceptedVersion to 2 and click Save
Jonathan Channon