[Javalist] Login with IWiW (OpenSocial 0.9)

aszomor at szomor.hu aszomor at szomor.hu
2012. Jan. 25., Sze, 15:03:12 CET


Hali,

Meg van:
IWiWMeEndpoint = new  
MessageReceivingEndpoint("http://api.sandbox.iwiw.hu/social/connect/rest/people/@me", HttpDeliveryMethods.GetRequest |  
HttpDeliveryMethods.AuthorizationHeaderRequest);


egy "connect" kellet bele ;s nem kell "a @self"


Attila.


Idézet (aszomor at szomor.hu):

> Hali,
>
> Sikerült a "belépés a iWiW kapuval" a DotNetOpenAuth használatával a  
> homokozóba (a Twitter-ből kiindulva), most szeretném lekérdezni a  
> "people/me/@self"-et mi belépési pontja, esetleg tudja valaki ?
>
> Köszönöm,
> Szomor Attila.
>
> namespace DotNetOpenAuth.ApplicationBlock {
> 	using System;
> 	using System.Collections.Generic;
> 	using System.Configuration;
> 	using System.Globalization;
> 	using System.IO;
> 	using System.Net;
> 	using System.Web;
> 	using System.Xml;
> 	using System.Xml.Linq;
> 	using System.Xml.XPath;
> 	using DotNetOpenAuth.Messaging;
> 	using DotNetOpenAuth.OAuth;
> 	using DotNetOpenAuth.OAuth.ChannelElements;
>
> 	/// <summary>
> 	/// A consumer capable of communicating with IWiW.
> 	/// </summary>
> 	public static class IWiWConsumer {
> 		/// <summary>
> 		/// The description of IWiW's OAuth protocol URIs for use with  
> their "Sign in with IWiW" feature.
> 		/// </summary>
> 		public static readonly ServiceProviderDescription  
> SignInWithIWiWServiceDescription = new ServiceProviderDescription {
> 			RequestTokenEndpoint = new  
> MessageReceivingEndpoint("http://api.sandbox.iwiw.hu/social/oauth/requestToken", HttpDeliveryMethods.GetRequest |  
> HttpDeliveryMethods.AuthorizationHeaderRequest),
> 			UserAuthorizationEndpoint = new  
> MessageReceivingEndpoint("http://sandbox.iwiw.hu/pages/auth/authorize.jsp",  
> HttpDeliveryMethods.GetRequest |  
> HttpDeliveryMethods.AuthorizationHeaderRequest),
> 			AccessTokenEndpoint = new  
> MessageReceivingEndpoint("http://api.sandbox.iwiw.hu/social/oauth/accessToken", HttpDeliveryMethods.GetRequest |  
> HttpDeliveryMethods.AuthorizationHeaderRequest),
> 			TamperProtectionElements = new  
> ITamperProtectionChannelBindingElement[] { new  
> HmacSha1SigningBindingElement() },
> 		};
>
> 		/// <summary>
> 		/// Initializes static members of the <see cref="IWiWConsumer"/> class.
> 		/// </summary>
> 		static IWiWConsumer() {
> 		}
>
> 		/// <summary>
> 		/// The URI to get the data on the user's home page.
> 		/// </summary>
> 		private static readonly MessageReceivingEndpoint IWiWMeEndpoint =  
> new  
> MessageReceivingEndpoint("http://api.sandbox.iwiw.hu/social/rest/people/me/@self", HttpDeliveryMethods.GetRequest |  
> HttpDeliveryMethods.AuthorizationHeaderRequest);
>
> 		public static XDocument IWiWMe(ConsumerBase IWiW, string accessToken) {
> 			IncomingWebResponse response =  
> IWiW.PrepareAuthorizedRequestAndSend(IWiWMeEndpoint, accessToken);
> 			return XDocument.Load(XmlReader.Create(response.GetResponseReader()));
> 		}
> 	}
> }
>
>
> namespace Mvc.Client.Library
> {
>     public class AccountController : BaseInputController
>     {
>         public ActionResult OAuth(string providerName, string returnUrl)
>         {
>             if (!String.IsNullOrEmpty(providerName))
>             {
>                 switch  
> (EnumTool.GetEnumByName<CommunalType>(providerName,  
> CommunalType.None))
>                 {
>                     case CommunalType.IWiW:
>                         //check for ReturnUrl, which we should have  
> if we use forms
>                         //authentication and [Authorise] on our controllers
>                         if (String.IsNullOrEmpty(returnUrl))
>                             Session["OpenAuthReturnUrl"] = returnUrl;
>                         Session["OpenAuthServiceProvider"] = providerName;
>                         var iwiw = new  
> WebConsumer(IWiWConsumer.SignInWithIWiWServiceDescription,  
> IWiWTokenManager);
>                         string iwiwUrl = RB.MVC.Const.BaseAddress +  
> "Account/OAuthCallback"; //Request.Url.ToString().Replace("OAuth",  
> "OAuthCallback");
>                         var iwiwCallBackUrl = new Uri(iwiwUrl);
>                          
> iwiw.Channel.Send(iwiw.PrepareRequestUserAuthorization(iwiwCallBackUrl,  
> null, null));
>                         break;
>                 }
>             }
>             return RedirectToHome();
>         }
>
>         public ActionResult OAuthCallback()
>         {
>             string providerName =  
> Session["OpenAuthServiceProvider"].ToString();
>             if (!String.IsNullOrEmpty(providerName))
>             {
>                 Session.Remove("OpenAuthServiceProvider");
>                 bool authorized = false;
>                 string userId = null;
>                 string screenName = null;
>                 string fullName = null;
>                 switch  
> (EnumTool.GetEnumByName<CommunalType>(providerName,  
> CommunalType.None))
>                 {
>                     case CommunalType.IWiW:
>                         var iwiw = new  
> WebConsumer(IWiWConsumer.SignInWithIWiWServiceDescription,  
> IWiWTokenManager);
>                         var iwiwAccessTokenResponse =  
> iwiw.ProcessUserAuthorization();
>                         if (iwiwAccessTokenResponse != null)
>                         {
>                             userId =  
> iwiwAccessTokenResponse.ExtraData["user_id"];
>                             screenName = "IWiW teszt";
>                             fullName =  
> iwiwAccessTokenResponse.ExtraData["screen_name"];
>                             authorized = true;
>                         }
>                         LoggerHelper.Error("OAuth: No access token  
> response!");
>                         break;
>                 }
>                 if (authorized && !String.IsNullOrEmpty(userId) &&  
> !String.IsNullOrEmpty(screenName) && !String.IsNullOrEmpty(fullName))
>                 {
>                     return OpenAuthSocialLoginUser(providerName,  
> userId, screenName, fullName);
>                 }
>             }
>             return RedirectToHome();
>         }
>
>         static private InMemoryTokenManager iWiWTokenManager = null;
>         static private InMemoryTokenManager IWiWTokenManager
>         {
>             get
>             {
>                 if (iWiWTokenManager == null)
>                 {
>                     string iWiWConsumerKey = null;
>                     string iWiWConsumerSecret = null;
>                     IClientConfigManager clientConfigManager =  
> Container.Resolve<IClientConfigManager>();
>                     if (clientConfigManager.Config != null &&
>                         
> clientConfigManager.Config.IsDotNetOpenAuthServiceProvidersActive())
>                     {
>                         ServiceProvidersServiceProvider iWiWCfg =  
> clientConfigManager.Config.GetDotNetOpenAuthServiceProviderByType(CommunalType.IWiW);
>                         if (iWiWCfg != null)
>                         {
>                             iWiWConsumerKey = iWiWCfg.ConsumerKey;
>                             iWiWConsumerSecret = iWiWCfg.ConsumerSecret;
>                         }
>                     }
>                     iWiWTokenManager = new  
> InMemoryTokenManager(iWiWConsumerKey, iWiWConsumerSecret);
>                 }
>                 return iWiWTokenManager;
>             }
>         }
>     }
> }
>
> _______________________________________________
> Javalist mailing list
> Javalist at lists.javaforum.hu
> http://lists.javaforum.hu/mailman/listinfo/javalist
>




További információk a(z) Javalist levelezőlistáról