Buckaroo .NET implementation
Buckaroo offers a simple solution for implementing iDeal payments on your website. In order to make use of the Buckaroo implementation, we need to write some code and apply configurations inside the p…
INDIVIRTUAL - TECHNISCH PARTNER IN DIGITALE DIENSTVERLENING
October 28, 2015
This document details how to set up Umbraco 7.3+ with OAuth 2.0.
Before we can start we need to set up our project:
Once the project is set up we need to make some changes. After installing Umbraco, the standard Startup class is no longer executed. Instead, Umbraco it’s own UmbracoDefaultOwinStartup class is executed. We are going to take back control by making the Startup class inherit from UmbracoDefaultOwinStartup and then changing the web.config file to execute our class instead of the UmbracoDefaultOwinStartup class.
First make the Startup class inherit from UmbracoDefaultOwinStartup and add the following code to it:
base.Configuration(app);
ConfigureAuth(app);
```
It’s important that <em>base.Configuration</em> is called before setting the OAUTH cookies with<em> ConfigureAuth.</em>
``` csharp
[assembly: OwinStartupAttribute(typeof(umbracotestproject.Startup))]
namespace umbracotestproject
{
public partial class Startup : UmbracoDefaultOwinStartup
{
public override void Configuration(IAppBuilder app)
{
base.Configuration(app);
ConfigureAuth(app);
}
}
}
```
Now we need to change the <em>owin:appStartup</em> key. Instead of the <em>UmbracoDefaultOwinStartup</em> class we have to add our own <em>Startup</em> class.
``` xml
<appSettings>
<add key="umbracoConfigurationStatus" value="7.3.0" />
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd" />
<add key="umbracoReservedPaths" value="~/umbraco,~/install/" />
<add key="umbracoPath" value="~/umbraco" />
<add key="umbracoHideTopLevelNodeFromPath" value="true" />
<add key="umbracoUseDirectoryUrls" value="true" />
<add key="umbracoTimeOutInMinutes" value="20" />
<add key="umbracoDefaultUILanguage" value="en" />
<add key="umbracoUseSSL" value="false" />
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
<add key="webpages:Enabled" value="false" />
<add key="enableSimpleMembership" value="false" />
<add key="autoFormsAuthentication" value="false" />
<add key="log4net.Config" value="config\log4net.config" />
<add key="owin:appStartup" value="umbracotestproject.Startup" />
</appSettings>
```
Now that our own <em>Startup</em> class is executed, we can enable OAUTH. In order to do this we need to uncomment some code that is already present in the Startup.Auth file.
``` csharp
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
//{
// ClientId = "",
// ClientSecret = ""
//});
```
Uncomment the<em> app.UseGoogleAuthentication </em>code and fill in the <em>ClientId</em> and <em>ClientSecret</em> of your Google App.
``` csharp
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "",
ClientSecret = ""
});
```
Change the <em>AccountController </em>so that it inherits from the Umbraco <em>SurfaceController</em>.
``` csharp
[Authorize]
public class AccountController : SurfaceController
{
private ApplicationSignInManager _signInManager;
private ApplicationUserManager _userManager;
// Removed code for improved readability for this tutorial
}
```
In my own project I had to remove the forms authentication code from the <em>Web.Config</em> file.
``` xml
<!-- <authentication mode="Forms">
<forms name="yourAuthCookie" loginUrl="login.aspx" protection="All" path="/" />
</authentication> -->
<authorization>
<allow users="?" />
</authorization>
```
In order to show the Google login button we can add the following code to our master template:
``` csharp
if (Members.IsLoggedIn())
{
Html.RenderPartial("~/Views/Account/_ExternalLoggedInPartial.cshtml", Model);
}
else
{
<section id="socialLoginForm">
@Html.Partial("~/Views/Account/_ExternalLoginsListPartial.cshtml", new ExternalLoginListViewModel { ReturnUrl = Model.Url })
</section>
}
```
Build and run the project and see if you can login using Google.