Gets custom OAuth errors working
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Web
|
||||
@@ -21,6 +25,49 @@ namespace Umbraco.Web
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies data from a request cookie to view data and then clears the cookie in the response
|
||||
/// </summary>
|
||||
/// <param name="viewData"></param>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <param name="cookieName"></param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This is similar to TempData but in some cases we cannot use TempData which relies on the temp data provider and session.
|
||||
/// The cookie value can either be a simple string value
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
internal static bool FromBase64CookieData<T>(this ViewDataDictionary viewData, HttpContextBase httpContext, string cookieName)
|
||||
{
|
||||
var hasCookie = httpContext.Request.HasCookie(cookieName);
|
||||
if (!hasCookie) return false;
|
||||
|
||||
// get the cookie value
|
||||
var cookieVal = httpContext.Request.GetCookieValue(cookieName);
|
||||
|
||||
if (cookieVal == null)
|
||||
return false;
|
||||
|
||||
// ensure the cookie is expired (must be done after reading the value)
|
||||
httpContext.ExpireCookie(cookieName);
|
||||
|
||||
if (cookieVal.IsNullOrWhiteSpace())
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(System.Net.WebUtility.UrlDecode(cookieVal)));
|
||||
// deserialize to T and store in viewdata
|
||||
viewData[cookieName] = JsonConvert.DeserializeObject<T>(decoded);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetUmbracoPath(this ViewDataDictionary viewData)
|
||||
{
|
||||
return (string)viewData[TokenUmbracoPath];
|
||||
|
||||
Reference in New Issue
Block a user