├── .github
├── CODEOWNERS
├── ISSUE_TEMPLATE
│ ├── config.yml
│ ├── Feature Request.yml
│ └── Bug Report.yml
├── workflows
│ └── semgrep.yml
└── stale.yml
├── Quickstart
└── Sample
│ ├── MvcApplication
│ ├── Views
│ │ ├── _ViewStart.cshtml
│ │ ├── Shared
│ │ │ ├── Error.cshtml
│ │ │ └── _Layout.cshtml
│ │ ├── Account
│ │ │ ├── UserProfile.cshtml
│ │ │ └── Claims.cshtml
│ │ ├── Home
│ │ │ └── Index.cshtml
│ │ └── Web.config
│ ├── Global.asax
│ ├── favicon.ico
│ ├── Controllers
│ │ ├── HomeController.cs
│ │ └── AccountController.cs
│ ├── ViewModels
│ │ └── UserProfileViewModel.cs
│ ├── App_Start
│ │ ├── FilterConfig.cs
│ │ ├── RouteConfig.cs
│ │ └── BundleConfig.cs
│ ├── Scripts
│ │ ├── _references.js
│ │ ├── respond.min.js
│ │ ├── respond.matchmedia.addListener.min.js
│ │ ├── respond.js
│ │ ├── respond.matchmedia.addListener.js
│ │ ├── jquery.validate.min.js
│ │ └── jquery.validate.unobtrusive.min.js
│ ├── Global.asax.cs
│ ├── Content
│ │ ├── Site.css
│ │ ├── bootstrap-reboot.min.css
│ │ ├── bootstrap-reboot.rtl.min.css
│ │ ├── bootstrap-reboot.rtl.css
│ │ ├── bootstrap-reboot.css
│ │ └── bootstrap-theme.min.css
│ ├── README.md
│ ├── Web.Debug.config
│ ├── Web.Release.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Support
│ │ ├── SameSiteCookieManager.cs
│ │ └── SameSiteSupport.cs
│ ├── packages.config
│ ├── Startup.cs
│ ├── Project_Readme.html
│ └── Web.config
│ └── MvcApplication.sln
├── README.md
├── LICENSE
└── .gitignore
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @auth0-samples/dx-sdks-engineer
2 |
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/Views/_ViewStart.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | Layout = "~/Views/Shared/_Layout.cshtml";
3 | }
4 |
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/Global.asax:
--------------------------------------------------------------------------------
1 | <%@ Application Codebehind="Global.asax.cs" Inherits="MvcApplication.MvcApplication" Language="C#" %>
2 |
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/auth0-samples/auth0-aspnet-owin-mvc-samples/HEAD/Quickstart/Sample/MvcApplication/favicon.ico
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: 🤔 Help & Questions
4 | url: https://community.auth0.com
5 | about: Ask general support or usage questions in the Auth0 Community forums.
6 |
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Mvc;
2 |
3 | namespace MvcApplication.Controllers
4 | {
5 | public class HomeController : Controller
6 | {
7 | public ActionResult Index()
8 | {
9 | return View();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/ViewModels/UserProfileViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace MvcApplication.ViewModels
2 | {
3 | public class UserProfileViewModel
4 | {
5 | public string EmailAddress { get; set; }
6 |
7 | public string Name { get; set; }
8 |
9 | public string ProfileImage { get; set; }
10 | }
11 | }
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/App_Start/FilterConfig.cs:
--------------------------------------------------------------------------------
1 | using System.Web.Mvc;
2 |
3 | namespace MvcApplication
4 | {
5 | public class FilterConfig
6 | {
7 | public static void RegisterGlobalFilters(GlobalFilterCollection filters)
8 | {
9 | filters.Add(new HandleErrorAttribute());
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # auth0-aspnet-owin-mvc-sample
2 | Quickstart sample for ASP.NET (OWIN) MVC
3 |
4 | ## Changelog
5 |
6 | ### 2019-02-07
7 |
8 | **Changed**
9 | - Update to .Net Framework 4.7 for better TLS support based on recommendations by Microsoft at https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls#for-net-framework-35---452-and-not-wcf.
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
Getting started
14 |
15 | ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
16 | enables a clean separation of concerns and gives you full control over markup
17 | for enjoyable, agile development.
18 |
19 |
Learn more »
20 |
21 |
22 |
Get more libraries
23 |
NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.
24 |
Learn more »
25 |
26 |
27 |
Web Hosting
28 |
You can easily find a web hosting company that offers the right mix of features and price for your applications.
29 |
Learn more »
30 |
31 |
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/Support/SameSiteCookieManager.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Owin;
2 | using Microsoft.Owin.Infrastructure;
3 |
4 | namespace MvcApplication.Support
5 | {
6 | public class SameSiteCookieManager : ICookieManager
7 | {
8 | private readonly ICookieManager _innerManager;
9 |
10 | public SameSiteCookieManager() : this(new CookieManager())
11 | {
12 | }
13 |
14 | public SameSiteCookieManager(ICookieManager innerManager)
15 | {
16 | _innerManager = innerManager;
17 | }
18 |
19 | public void AppendResponseCookie(IOwinContext context, string key, string value,
20 | CookieOptions options)
21 | {
22 | CheckSameSite(context, options);
23 | _innerManager.AppendResponseCookie(context, key, value, options);
24 | }
25 |
26 | public void DeleteCookie(IOwinContext context, string key, CookieOptions options)
27 | {
28 | CheckSameSite(context, options);
29 | _innerManager.DeleteCookie(context, key, options);
30 | }
31 |
32 | public string GetRequestCookie(IOwinContext context, string key)
33 | {
34 | return _innerManager.GetRequestCookie(context, key);
35 | }
36 |
37 | private void CheckSameSite(IOwinContext context, CookieOptions options)
38 | {
39 | if (options.SameSite == Microsoft.Owin.SameSiteMode.None &&
40 | SameSite.BrowserDetection.DisallowsSameSiteNone(context.Request.Headers["User-Agent"]))
41 | {
42 | options.SameSite = null;
43 | } else if (options.SameSite == Microsoft.Owin.SameSiteMode.None && options.Secure == false)
44 | {
45 | options.SameSite = null;
46 | }
47 | }
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/Controllers/AccountController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Security.Claims;
5 | using System.Web;
6 | using System.Web.Mvc;
7 | using Microsoft.Owin.Security;
8 | using Microsoft.Owin.Security.Cookies;
9 | using MvcApplication.ViewModels;
10 |
11 | namespace MvcApplication.Controllers
12 | {
13 | public class AccountController : Controller
14 | {
15 | public ActionResult Login(string returnUrl)
16 | {
17 | HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties
18 | {
19 | RedirectUri = returnUrl ?? Url.Action("Index", "Home")
20 | },
21 | "Auth0");
22 | return new HttpUnauthorizedResult();
23 | }
24 |
25 | [Authorize]
26 | public void Logout()
27 | {
28 | HttpContext.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
29 | HttpContext.GetOwinContext().Authentication.SignOut("Auth0");
30 | }
31 |
32 | [Authorize]
33 | public ActionResult UserProfile()
34 | {
35 | var claimsIdentity = User.Identity as ClaimsIdentity;
36 |
37 | return View(new UserProfileViewModel()
38 | {
39 | Name = claimsIdentity?.FindFirst(c => c.Type == claimsIdentity.NameClaimType)?.Value,
40 | EmailAddress = claimsIdentity?.FindFirst(c => c.Type == ClaimTypes.Email)?.Value,
41 | ProfileImage = claimsIdentity?.FindFirst(c => c.Type == "picture")?.Value
42 | });
43 | }
44 |
45 | [Authorize]
46 | public ActionResult Claims()
47 | {
48 | return View();
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/Feature Request.yml:
--------------------------------------------------------------------------------
1 | name: 🧩 Feature request
2 | description: Suggest an idea or a feature for this sample
3 | labels: ["feature request"]
4 |
5 | body:
6 | - type: checkboxes
7 | id: checklist
8 | attributes:
9 | label: Checklist
10 | options:
11 | - label: I have searched the [issues](https://github.com/auth0-samples/auth0-aspnet-owin-mvc-samples/issues) and have not found a suitable solution or answer.
12 | required: true
13 | - label: I have searched the [Auth0 Community](https://community.auth0.com) forums and have not found a suitable solution or answer.
14 | required: true
15 | - label: I agree to the terms within the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md).
16 | required: true
17 |
18 | - type: textarea
19 | id: description
20 | attributes:
21 | label: Describe the problem you'd like to have solved
22 | description: A clear and concise description of what the problem is.
23 | validations:
24 | required: true
25 |
26 | - type: textarea
27 | id: ideal-solution
28 | attributes:
29 | label: Describe the ideal solution
30 | description: A clear and concise description of what you want to happen.
31 | validations:
32 | required: true
33 |
34 | - type: textarea
35 | id: alternatives-and-workarounds
36 | attributes:
37 | label: Alternatives and current workarounds
38 | description: A clear and concise description of any alternatives you've considered or any workarounds that are currently in place.
39 | validations:
40 | required: false
41 |
42 | - type: textarea
43 | id: additional-context
44 | attributes:
45 | label: Additional context
46 | description: Add any other context or screenshots about the feature request here.
47 | validations:
48 | required: false
49 |
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/Views/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
40 | @RenderBody()
41 |
42 |
45 |
46 |
47 | @Scripts.Render("~/bundles/jquery")
48 | @Scripts.Render("~/bundles/bootstrap")
49 | @RenderSection("scripts", required: false)
50 |
51 |
52 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/Bug Report.yml:
--------------------------------------------------------------------------------
1 | name: 🐞 Report a bug
2 | description: Have you found a bug or issue? Create a bug report for this sample
3 |
4 | body:
5 | - type: markdown
6 | attributes:
7 | value: |
8 | **Please do not report security vulnerabilities here**. The [Responsible Disclosure Program](https://auth0.com/responsible-disclosure-policy) details the procedure for disclosing security issues.
9 |
10 | - type: checkboxes
11 | id: checklist
12 | attributes:
13 | label: Checklist
14 | options:
15 | - label: I have searched the [issues](https://github.com/auth0-samples/auth0-aspnet-owin-mvc-samples/issues) and have not found a suitable solution or answer.
16 | required: true
17 | - label: I have searched the [Auth0 Community](https://community.auth0.com) forums and have not found a suitable solution or answer.
18 | required: true
19 | - label: I agree to the terms within the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md).
20 | required: true
21 |
22 | - type: textarea
23 | id: description
24 | attributes:
25 | label: Description
26 | description: Provide a clear and concise description of the issue, including what you expected to happen.
27 | validations:
28 | required: true
29 |
30 | - type: textarea
31 | id: reproduction
32 | attributes:
33 | label: Reproduction
34 | description: Detail the steps taken to reproduce this error, and whether this issue can be reproduced consistently or if it is intermittent.
35 | placeholder: |
36 | 1. Step 1...
37 | 2. Step 2...
38 | 3. ...
39 | validations:
40 | required: true
41 |
42 | - type: textarea
43 | id: additional-context
44 | attributes:
45 | label: Additional context
46 | description: Any other relevant information you think would be useful.
47 | validations:
48 | required: false
49 |
50 | - type: dropdown
51 | id: environment-sample
52 | attributes:
53 | label: Sample
54 | multiple: false
55 | options:
56 | - Started seed
57 | - Login
58 | - User profile
59 | - Authorization
60 | validations:
61 | required: true
62 |
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/Support/SameSiteSupport.cs:
--------------------------------------------------------------------------------
1 | namespace MvcApplication.Support.SameSite
2 | {
3 | public static class BrowserDetection
4 | {
5 | // Same as https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/
6 | public static bool DisallowsSameSiteNone(string userAgent)
7 | {
8 | if (string.IsNullOrEmpty(userAgent))
9 | {
10 | return true;
11 | }
12 |
13 | // Note that these detections are a starting point. See https://www.chromium.org/updates/same-site/incompatible-clients for more detections.
14 |
15 | // Cover all iOS based browsers here. This includes:
16 | // - Safari on iOS 12 for iPhone, iPod Touch, iPad
17 | // - WkWebview on iOS 12 for iPhone, iPod Touch, iPad
18 | // - Chrome on iOS 12 for iPhone, iPod Touch, iPad
19 | // All of which are broken by SameSite=None, because they use the iOS networking stack
20 | if (userAgent.Contains("CPU iPhone OS 12") || userAgent.Contains("iPad; CPU OS 12"))
21 | {
22 | return true;
23 | }
24 |
25 | // Cover Mac OS X based browsers that use the Mac OS networking stack. This includes:
26 | // - Safari on Mac OS X.
27 | // This does not include:
28 | // - Chrome on Mac OS X
29 | // Because they do not use the Mac OS networking stack.
30 | if (userAgent.Contains("Macintosh; Intel Mac OS X 10_14") &&
31 | userAgent.Contains("Version/") && userAgent.Contains("Safari"))
32 | {
33 | return true;
34 | }
35 |
36 | // Cover Chrome 50-69, because some versions are broken by SameSite=None,
37 | // and none in this range require it.
38 | // Note: this covers some pre-Chromium Edge versions,
39 | // but pre-Chromium Edge does not require SameSite=None.
40 | if (userAgent.Contains("Chrome/5") || userAgent.Contains("Chrome/6"))
41 | {
42 | return true;
43 | }
44 |
45 | // Unreal Engine runs Chromium 59, but does not advertise as Chrome until 4.23. Treat versions of Unreal
46 | // that don't specify their Chrome version as lacking support for SameSite=None.
47 | if (userAgent.Contains("UnrealEngine") && !userAgent.Contains("Chrome"))
48 | {
49 | return true;
50 | }
51 |
52 | return false;
53 | }
54 |
55 | public static bool AllowsSameSiteNone(string userAgent)
56 | {
57 | return !DisallowsSameSiteNone(userAgent);
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/Quickstart/Sample/MvcApplication/packages.config:
--------------------------------------------------------------------------------
1 |
2 |