Prerequisites
As I wrote in my last GitHub related post, I had to recreate the project, as far as logging with Individual accounts option was necessary. This is the screenshot during project creation:
The second thing is extracting the ClientID and SecretID to Azure App settings:
(we don’t want to have keys put explicitly in the code) and retrieving them right from there:
public string GetSetting(string settingId) { string res; var settings = ConfigurationManager.AppSettings; try { res = settings[settingId]; } catch (Exception ex) { throw new Exception("There is no setting named: " + settingId, ex); } return res; }
so my GitHub part looks like below:
app.UseGitHubAuthentication( new GitHubAuthenticationOptions { ClientId = GetSetting(GitHubClientIdName), ClientSecret = GetSetting(GitHubSecretIdName), Scope = { "user:email" } });
Having that deployed, I experienced problems described below…
Troubles
No specific error
When I published the app for the first time I saw this error:
As you can guess I haven’t concluded too much helpful information from here. However, I’ve been aware of the necessity of turning the custom errors off to see more detailed faults in ASP.NET. Only then I can see the exception and stack trace thrown by an application. So I did:
<system.web> <customErrors mode="Off" /> </system.web>
And service has totally corrupted now. Nothing was working. I reverted back the application to the last working stage and asked for help in few places.
Eventually, it turned out I misplaced the XML tags (can’t really tell you how it happened – but it did) and when I fixed that – the more detailed error has been shown. We are one step closer.
Side note:
mysupersite.azurewebsites.net
just put ‘scm’ in between like this: mysupersite.scm.azurewebsites.net
and you’ll reach the app. There is file explorer, console, file editor (helpful to edit Web.config for instance – without any re-deployment) and many more – there is a gallery with extensions 🙂 I really recommend if you use the Azure Cloud.SQL exception
When this was fixed, I was really curious what will be shown now as an exception. And I get this lovely and well-known screen:
When I saw SQL Client error I started to doubt if I really have AppService with functioning SQL. It turned out it’s not. I created the new one, with SQL inside, and… it works! 🙂
The service is named: Web App + SQL. Please have that in mind when you’ll be creating service for yourself.
Setting the AppService with database
This database-related stuff hasn’t been covered earlier, so I show you few screens from creating such.
During creation you’ll be asked to fill in the data for Database – admin account, server location and its name:
Then pick the pricing:
And that’s it. When you confirm you’ll have working Web&Mobile service with SQL database.
Additional work
As far as AppService has changed for me, I need to reconfigure my CD processes, so the code will be deployed to the proper one. It is not a big overhead luckily so… we’ll manage 🙂
Summary
The error I was repeatedly getting had its root in badly configured app service. It hasn’t been prepared to host application with databases – and my uses such when is storing logged users. Each time the callback from GtiHub was coming back to my site, the backend was trying to immediately store the user’s email to the database. And it has been failing at this step. Thus I thought all the time there is a problem with OAuth, GitHub library or lacking https protocol on my website. Happily, another trouble is gone now. 🙂