Shopify OAuth provider - OWIN integration / implementation

This commit is contained in:
Jaspalsinh Chauhan
2015-08-13 00:25:57 +05:30
parent 9ccb01fd84
commit 0600b9b06c
15 changed files with 723 additions and 11 deletions

View File

@@ -30,6 +30,7 @@ using Owin.Security.Providers.SoundCloud;
using Owin.Security.Providers.Spotify;
using Owin.Security.Providers.StackExchange;
using Owin.Security.Providers.Steam;
using Owin.Security.Providers.Shopify;
using Owin.Security.Providers.TripIt;
using Owin.Security.Providers.Twitch;
using Owin.Security.Providers.Untappd;
@@ -53,7 +54,7 @@ namespace OwinOAuthProvidersDemo
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
//app.UseDeviantArtAuthentication("id", "secret");
//app.UseDeviantArtAuthentication("id", "secret");
//app.UseUntappdAuthentication("id", "secret");
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
@@ -185,6 +186,8 @@ namespace OwinOAuthProvidersDemo
//};
//app.UseSalesforceAuthentication(salesforceOptions);
////app.UseShopifyAuthentication("", "");
//app.UseArcGISOnlineAuthentication(
// clientId: "",
// clientSecret: "");
@@ -201,7 +204,6 @@ namespace OwinOAuthProvidersDemo
// clientId: "",
// clientSecret: "");
//app.UseBattleNetAuthentication(new BattleNetAuthenticationOptions
//{
// ClientId = "",

View File

@@ -182,15 +182,26 @@ namespace OwinOAuthProvidersDemo.Controllers
return View(model);
}
//////
////// POST: /Account/ExternalLogin
////[HttpPost]
////[AllowAnonymous]
////[ValidateAntiForgeryToken]
////public ActionResult ExternalLogin(string provider, string returnUrl)
////{
//// // Request a redirect to the external login provider
//// return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
////}
//
// POST: /Account/ExternalLogin
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider, string returnUrl)
public ActionResult ExternalLogin(string provider, string returnUrl, string shopName = "")
{
// Request a redirect to the external login provider
return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }), null, shopName);
}
//
@@ -224,10 +235,10 @@ namespace OwinOAuthProvidersDemo.Controllers
// POST: /Account/LinkLogin
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LinkLogin(string provider)
public ActionResult LinkLogin(string provider, string shopName)
{
// Request a redirect to the external login provider to link a login for the current user
return new ChallengeResult(provider, Url.Action("LinkLoginCallback", "Account"), User.Identity.GetUserId());
return new ChallengeResult(provider, Url.Action("LinkLoginCallback", "Account"), User.Identity.GetUserId(), shopName);
}
//
@@ -324,6 +335,8 @@ namespace OwinOAuthProvidersDemo.Controllers
#region Helpers
// Used for XSRF protection when adding external logins
private const string XsrfKey = "XsrfId";
// Used for Shopify external login to provide shopname while building endpoints.
private const string ShopNameKey = "ShopName";
private IAuthenticationManager AuthenticationManager
{
@@ -380,28 +393,36 @@ namespace OwinOAuthProvidersDemo.Controllers
private class ChallengeResult : HttpUnauthorizedResult
{
public ChallengeResult(string provider, string redirectUri) : this(provider, redirectUri, null)
public ChallengeResult(string provider, string redirectUri) : this(provider, redirectUri, null, null)
{
}
public ChallengeResult(string provider, string redirectUri, string userId)
public ChallengeResult(string provider, string redirectUri, string userId, string shopName)
{
LoginProvider = provider;
RedirectUri = redirectUri;
UserId = userId;
ShopName = shopName;
}
public string LoginProvider { get; set; }
public string RedirectUri { get; set; }
public string UserId { get; set; }
public string ShopName { get; set; }
public override void ExecuteResult(ControllerContext context)
{
var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
if (UserId != null)
{
properties.Dictionary[XsrfKey] = UserId;
properties.Dictionary[XsrfKey] = this.UserId;
}
if (!string.IsNullOrWhiteSpace(this.ShopName))
{
properties.Dictionary[ShopNameKey] = this.ShopName;
}
context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
}
}

View File

@@ -24,6 +24,10 @@
<p>
@foreach (AuthenticationDescription p in loginProviders)
{
if (p.AuthenticationType.Equals("Shopify"))
{
@Html.TextBox("shopName")
}
<button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
}
</p>