protected override string GetAuthUrl(string appName, string returnAddress, string parameters, string activity, string email, bool signupIfNotSignedIn, bool useHashRouting) { AdfsApplicationKeys keys = (AdfsApplicationKeys)GetSocialKeys(appName); string clientId = keys.ClientId; string oauth2EndPoint = keys.Host; string resource = keys.Resource; Dictionary <string, object> state = new Dictionary <string, object>() { { "stam", "stam" }, { "appName", appName }, { "returnAddress", System.Web.HttpContext.Current.Server.UrlEncode(returnAddress) }, { "activity", activity }, { "parameters", parameters ?? string.Empty }, { "email", email ?? string.Empty }, { "signupIfNotSignedIn", true }, { "useHashRouting", useHashRouting } }; string redirectUri = GetRedirectUrl(appName); string qsState = ConvertDictionaryToQueryString(state); //var jss = new JavaScriptSerializer(); string authorizationEndpoint = oauth2EndPoint + "/authorize" + "?response_type=code" + "&client_id=" + Uri.EscapeDataString(clientId) + "&redirect_uri=" + Uri.EscapeDataString(redirectUri) + // + "?state=" + jss.Serialize(state)) + (string.IsNullOrEmpty(resource) ? string.Empty : ("&resource=" + Uri.EscapeDataString(resource))) + "&state=" + Uri.EscapeDataString(qsState); return(authorizationEndpoint); }
public override string GetLogOutRedirectUrl(string appName, string redirectUri = null) { AdfsApplicationKeys keys = (AdfsApplicationKeys)GetSocialKeys(appName); string clientId = keys.ClientId; string oauth2EndPoint = keys.Host; string url = oauth2EndPoint + "/logout"; if (!string.IsNullOrEmpty(redirectUri)) { url += "?post_logout_redirect_uri=" + redirectUri; } return(url); }
protected override SocialProfile FetchProfileByCode(string code, string appName, string returnUrl, string activity, string parameters, string redirectUrl, string email, bool signupIfNotSignedIn, bool useHashRouting) { AdfsApplicationKeys keys = (AdfsApplicationKeys)GetSocialKeys(appName); string clientId = keys.ClientId; string oauth2EndPoint = keys.Host; string urlAccessToken = oauth2EndPoint + "/token"; string redirectUri = GetRedirectUrl(appName); string accessTokenData = GetAccessTokenData(code, clientId, redirectUri, keys.Resource); string response = null; try { response = Durados.Web.Mvc.Infrastructure.Http.PostWebRequest(urlAccessToken, accessTokenData); } catch (System.Net.WebException exception) { try { string errorDescription = new System.IO.StreamReader((exception).Response.GetResponseStream()).ReadToEnd(); throw new AdfsException(errorDescription); } catch { } throw exception; } //get the access token from the return JSON //JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); //AuthResponse validateResponse = (AuthResponse)jsonSerializer.Deserialize<AuthResponse>(response); Dictionary <string, object> validateResponse = Durados.Web.Mvc.UI.Json.JsonSerializer.Deserialize(response); string accessToken = validateResponse["access_token"].ToString(); string refreshToken = validateResponse["refresh_token"].ToString(); var profile = GetProfile(appName, accessToken, refreshToken, returnUrl, activity, parameters, email, signupIfNotSignedIn, useHashRouting); return(profile); }