public void AuthGetAccessToken(AuthArgs args) { var requestToken = args.InternalData["requestToken"] as string; var requestTokenSecret = args.InternalData["requestTokenSecret"] as string; var hyvesSession = this.LoadHyvesSession(args); var hyvesRequest = new HyvesRequest(hyvesSession); string userId; string accessTokenSecret; DateTime expireDate; var accessToken = hyvesRequest.CreateAccessToken(requestToken, requestTokenSecret, out accessTokenSecret, out userId, out expireDate); var authCompletedArgs = new AuthCompletedArgs { Application = args.Application, AccessToken = accessToken, AccessTokenSecret = accessTokenSecret, CallbackPage = args.CallbackPage, ExternalData = args.ExternalData, AttachAccountToLoggedInUser = args.AttachAccountToLoggedInUser, IsAsyncProfileUpdate = args.IsAsyncProfileUpdate }; if (!string.IsNullOrEmpty(args.CallbackType)) { this.InvokeAuthCompleted(args.CallbackType, authCompletedArgs); } }
public IEnumerable <Field> GetAccountInfo(Account account, IEnumerable <FieldInfo> acceptedFields) { var hyvesSession = this.GetHyvesSession(account); // receives the method dictionatyt where key: method name (described in config), value: method enum value Dictionary <string, HyvesMethod> methodDescriptionDictionary = this.GetMethodDescriptionDictionary(); var fieldsGroupedByAccess = acceptedFields.Where(field => field["method"] != null) .GroupBy(field => field["method"]) .Select(fg => new { Method = fg.Key, Fields = fg.ToList() }); foreach (var groupFields in fieldsGroupedByAccess) { var request = new HyvesRequest(hyvesSession); var hyvesResponse = request.InvokeMethod(methodDescriptionDictionary[groupFields.Method], false); // You'll find documentation here: // http://james.newtonking.com/projects/json/help/ var jObject = JObject.Parse(hyvesResponse.RawResponse); foreach (var field in groupFields.Fields) { var token = jObject.SelectToken(field["selectToken"]); var value = (token != null) ? token.ToString() : null; value = this.TryToRemoveBrackets(value); if (!string.IsNullOrEmpty(value)) { yield return(new Field { Name = field.SitecoreKey, Value = value }); } } } }
public void AuthGetCode(AuthArgs args) { var hyvesMethods = new List<HyvesMethod> { HyvesMethod.All }; var hyvesSession = new HyvesServerSession(args.Application.ApplicationKey, args.Application.ApplicationSecret, hyvesMethods); var hyvesRequest = new HyvesRequest(hyvesSession); string tokenSecret; var requestToken = hyvesRequest.CreateRequestToken(out tokenSecret, HyvesExpirationType.Infinite); args.InternalData["requestToken"] = requestToken; args.InternalData["requestTokenSecret"] = tokenSecret; this.SaveHyvesSession(args, hyvesSession); var request = HttpContext.Current.Request; var oauthCallback = string.Format("{0}://{1}{2}?type=access&state={3}", request.Url.Scheme, request.Url.Host, Paths.SocialLoginHandlerPath, args.StateKey); var hyvesAuthUrl = string.Format("http://www.hyves.nl/api/authorize/?oauth_token={0}&oauth_callback={1}", requestToken, HttpUtility.UrlEncode(oauthCallback)); HttpContext.Current.Response.Redirect(hyvesAuthUrl); }
public void AuthGetCode(AuthArgs args) { var hyvesMethods = new List <HyvesMethod> { HyvesMethod.All }; var hyvesSession = new HyvesServerSession(args.Application.ApplicationKey, args.Application.ApplicationSecret, hyvesMethods); var hyvesRequest = new HyvesRequest(hyvesSession); string tokenSecret; var requestToken = hyvesRequest.CreateRequestToken(out tokenSecret, HyvesExpirationType.Infinite); args.InternalData["requestToken"] = requestToken; args.InternalData["requestTokenSecret"] = tokenSecret; this.SaveHyvesSession(args, hyvesSession); var request = HttpContext.Current.Request; var oauthCallback = string.Format("{0}://{1}{2}?type=access&state={3}", request.Url.Scheme, request.Url.Host, Paths.SocialLoginHandlerPath, args.StateKey); var hyvesAuthUrl = string.Format("http://www.hyves.nl/api/authorize/?oauth_token={0}&oauth_callback={1}", requestToken, HttpUtility.UrlEncode(oauthCallback)); HttpContext.Current.Response.Redirect(hyvesAuthUrl); }
public void AuthGetAccessToken(AuthArgs args) { var requestToken = args.InternalData["requestToken"] as string; var requestTokenSecret = args.InternalData["requestTokenSecret"] as string; var hyvesSession = this.LoadHyvesSession(args); var hyvesRequest = new HyvesRequest(hyvesSession); string userId; string accessTokenSecret; DateTime expireDate; var accessToken = hyvesRequest.CreateAccessToken(requestToken, requestTokenSecret, out accessTokenSecret, out userId, out expireDate); var authCompletedArgs = new AuthCompletedArgs { Application = args.Application, AccessToken = accessToken, AccessTokenSecret = accessTokenSecret, CallbackPage = args.CallbackPage, ExternalData = args.ExternalData, AttachAccountToLoggedInUser = args.AttachAccountToLoggedInUser, IsAsyncProfileUpdate = args.IsAsyncProfileUpdate }; if (!string.IsNullOrEmpty(args.CallbackType)) { this.InvokeAuthCompleted(args.CallbackType, authCompletedArgs); } }
public IEnumerable<Field> GetAccountInfo(Account account, IEnumerable<FieldInfo> acceptedFields) { var hyvesSession = this.GetHyvesSession(account); // receives the method dictionatyt where key: method name (described in config), value: method enum value Dictionary<string, HyvesMethod> methodDescriptionDictionary = this.GetMethodDescriptionDictionary(); var fieldsGroupedByAccess = acceptedFields.Where(field => field["method"] != null) .GroupBy(field => field["method"]) .Select(fg => new { Method = fg.Key, Fields = fg.ToList() }); foreach (var groupFields in fieldsGroupedByAccess) { var request = new HyvesRequest(hyvesSession); var hyvesResponse = request.InvokeMethod(methodDescriptionDictionary[groupFields.Method], false); // You'll find documentation here: // http://james.newtonking.com/projects/json/help/ var jObject = JObject.Parse(hyvesResponse.RawResponse); foreach (var field in groupFields.Fields) { var token = jObject.SelectToken(field["selectToken"]); var value = (token != null) ? token.ToString() : null; value = this.TryToRemoveBrackets(value); if (!string.IsNullOrEmpty(value)) { yield return new Field { Name = field.SitecoreKey, Value = value }; } } } }