December 19, 2016

Social connect Module for Dxa - Internals - Part 2

Social connect Module was developed using Microsoft's OWIN implementation, which actually make it easy to write code.

Nuget packages

 <package id="Microsoft.Owin" version="3.0.1" targetFramework="net45" />  
  <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net45" />
  <package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Facebook" version="3.0.1" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Google" version="3.0.1" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.OAuth" version="2.1.0" targetFramework="net45" />

This is most important file of the module. it plugs the module in mvc lifecycle to ensure user is logged in and prompt whenever required for login.

 [assembly: OwinStartup(typeof(Sdl.Web.Modules.Social.Startup))]  

startup.cs has method ConfigureAuth which has responsibility to Register Social networks and add required claims to be returned by the respective social network.

upto now, no Dxa involvement was required but now will start integrating Dxa step by step.

SocialController :
This controller acts as main interaction of the system. it triggers following as per the Component template of the module

  • Show the Social network options to user
  • Trigger required social network to prompt for credentials
  • Receive token from Social network to validate it & Read the claims and show log out options.
  • Log outs from system

for above 4 set of activities we need different Component templates.

For last three activities three different pages have been created so that only specified activity is triggered as per the need of user. First activity is part of Header page.

If you need to retrieve authentication status or User information following can be used.

  • Request.IsAuthenticated
  • User.Identity.GetUserName()

No comments: