diff options
Diffstat (limited to 'samples/OpenIdRelyingPartyWebForms')
6 files changed, 28 insertions, 52 deletions
diff --git a/samples/OpenIdRelyingPartyWebForms/Code/State.cs b/samples/OpenIdRelyingPartyWebForms/Code/State.cs index c8147e5..c8cef80 100644 --- a/samples/OpenIdRelyingPartyWebForms/Code/State.cs +++ b/samples/OpenIdRelyingPartyWebForms/Code/State.cs @@ -1,5 +1,6 @@ namespace OpenIdRelyingPartyWebForms { using System.Web; + using DotNetOpenAuth.OAuth; using DotNetOpenAuth.OpenId.Extensions.AttributeExchange; using DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy; using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration; @@ -28,8 +29,8 @@ namespace OpenIdRelyingPartyWebForms { set { HttpContext.Current.Session["PapePolicies"] = value; } } - public static string GoogleAccessToken { - get { return HttpContext.Current.Session["GoogleAccessToken"] as string; } + public static AccessToken GoogleAccessToken { + get { return (AccessToken)(HttpContext.Current.Session["GoogleAccessToken"] ?? new AccessToken()); } set { HttpContext.Current.Session["GoogleAccessToken"] = value; } } @@ -38,7 +39,7 @@ namespace OpenIdRelyingPartyWebForms { FetchResponse = null; FriendlyLoginName = null; PapePolicies = null; - GoogleAccessToken = null; + GoogleAccessToken = new AccessToken(); } } }
\ No newline at end of file diff --git a/samples/OpenIdRelyingPartyWebForms/Global.asax.cs b/samples/OpenIdRelyingPartyWebForms/Global.asax.cs index 6283987..8460d49 100644 --- a/samples/OpenIdRelyingPartyWebForms/Global.asax.cs +++ b/samples/OpenIdRelyingPartyWebForms/Global.asax.cs @@ -18,7 +18,7 @@ get { var googleWebConsumer = (WebConsumerOpenIdRelyingParty)HttpContext.Current.Application["GoogleWebConsumer"]; if (googleWebConsumer == null) { - googleWebConsumer = new WebConsumerOpenIdRelyingParty(GoogleConsumer.ServiceDescription, GoogleTokenManager); + googleWebConsumer = new WebConsumerOpenIdRelyingParty { ServiceProvider = GoogleConsumer.ServiceDescription }; HttpContext.Current.Application["GoogleWebConsumer"] = googleWebConsumer; } @@ -26,36 +26,6 @@ } } - internal static InMemoryTokenManager GoogleTokenManager { - get { - var tokenManager = (InMemoryTokenManager)HttpContext.Current.Application["GoogleTokenManager"]; - if (tokenManager == null) { - string consumerKey = ConfigurationManager.AppSettings["googleConsumerKey"]; - string consumerSecret = ConfigurationManager.AppSettings["googleConsumerSecret"]; - if (!string.IsNullOrEmpty(consumerKey)) { - tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret); - HttpContext.Current.Application["GoogleTokenManager"] = tokenManager; - } - } - - return tokenManager; - } - } - - internal static InMemoryTokenManager OwnSampleOPHybridTokenManager { - get { - var tokenManager = (InMemoryTokenManager)HttpContext.Current.Application["OwnSampleOPHybridTokenManager"]; - if (tokenManager == null) { - string consumerKey = new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Request.ApplicationPath).AbsoluteUri; - string consumerSecret = "some crazy secret"; - tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret); - HttpContext.Current.Application["OwnSampleOPHybridTokenManager"] = tokenManager; - } - - return tokenManager; - } - } - public static string ToString(NameValueCollection collection) { using (StringWriter sw = new StringWriter()) { foreach (string key in collection.Keys) { diff --git a/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs b/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs index 2cbac9a..2b3b51d 100644 --- a/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs +++ b/samples/OpenIdRelyingPartyWebForms/MembersOnly/DisplayGoogleContacts.aspx.cs @@ -10,7 +10,7 @@ public partial class DisplayGoogleContacts : System.Web.UI.Page { protected async void Page_Load(object sender, EventArgs e) { - if (!string.IsNullOrEmpty(State.GoogleAccessToken)) { + if (!string.IsNullOrEmpty(State.GoogleAccessToken.Token)) { this.MultiView1.ActiveViewIndex = 1; if (State.FetchResponse != null && State.FetchResponse.Attributes.Contains(WellKnownAttributes.Contact.Email)) { this.emailLabel.Text = State.FetchResponse.Attributes[WellKnownAttributes.Contact.Email].Values[0]; @@ -18,7 +18,11 @@ this.emailLabel.Text = "unavailable"; } this.claimedIdLabel.Text = this.User.Identity.Name; - var contactsDocument = await GoogleConsumer.GetContactsAsync(Global.GoogleWebConsumer, State.GoogleAccessToken, cancellationToken: Response.ClientDisconnectedToken); + var google = new GoogleConsumer { + ConsumerKey = Global.GoogleWebConsumer.ConsumerKey, + ConsumerSecret = Global.GoogleWebConsumer.ConsumerSecret, + }; + var contactsDocument = await google.GetContactsAsync(State.GoogleAccessToken); this.RenderContacts(contactsDocument); } } diff --git a/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj b/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj index cf12262..7c6d03a 100644 --- a/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj +++ b/samples/OpenIdRelyingPartyWebForms/OpenIdRelyingPartyWebForms.csproj @@ -100,9 +100,6 @@ </Content> </ItemGroup> <ItemGroup> - <Compile Include="..\DotNetOpenAuth.ApplicationBlock\InMemoryTokenManager.cs"> - <Link>Code\InMemoryTokenManager.cs</Link> - </Compile> <Compile Include="ajaxlogin.aspx.cs"> <DependentUpon>ajaxlogin.aspx</DependentUpon> <SubType>ASPXCodeBehind</SubType> diff --git a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs index bffd539..0e6eae0 100644 --- a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs +++ b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuth.aspx.cs @@ -4,6 +4,7 @@ using System.Web; using System.Web.Security; using DotNetOpenAuth.ApplicationBlock; + using DotNetOpenAuth.OAuth; using DotNetOpenAuth.OAuth.Messages; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Extensions.AttributeExchange; @@ -25,7 +26,7 @@ switch (authResponse.Status) { case AuthenticationStatus.Authenticated: State.FetchResponse = authResponse.GetExtension<FetchResponse>(); - AuthorizedTokenResponse accessToken = await Global.GoogleWebConsumer.ProcessUserAuthorizationAsync(authResponse, Response.ClientDisconnectedToken); + AccessTokenResponse accessToken = await Global.GoogleWebConsumer.ProcessUserAuthorizationAsync(authResponse, Response.ClientDisconnectedToken); if (accessToken != null) { State.GoogleAccessToken = accessToken.AccessToken; FormsAuthentication.SetAuthCookie(authResponse.ClaimedIdentifier, false); @@ -56,7 +57,7 @@ // that is properly registered with Google. // We will customize the realm to use http or https based on what the // return_to URL will be (which will be this page). - Realm realm = Request.Url.Scheme + Uri.SchemeDelimiter + Global.GoogleTokenManager.ConsumerKey + "/"; + Realm realm = Request.Url.Scheme + Uri.SchemeDelimiter + (new GoogleConsumer()).ConsumerKey + "/"; IAuthenticationRequest authReq = await relyingParty.CreateRequestAsync(GoogleOPIdentifier, realm, cancellationToken: Response.ClientDisconnectedToken); // Prepare the OAuth extension diff --git a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuthSampleOP.aspx.cs b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuthSampleOP.aspx.cs index 91ec642..6133a86 100644 --- a/samples/OpenIdRelyingPartyWebForms/loginPlusOAuthSampleOP.aspx.cs +++ b/samples/OpenIdRelyingPartyWebForms/loginPlusOAuthSampleOP.aspx.cs @@ -1,5 +1,6 @@ namespace OpenIdRelyingPartyWebForms { using System; + using System.Web; using System.Web.Security; using DotNetOpenAuth.ApplicationBlock; using DotNetOpenAuth.Messaging; @@ -23,24 +24,19 @@ } protected void identifierBox_LoggingIn(object sender, OpenIdEventArgs e) { - ServiceProviderDescription serviceDescription = new ServiceProviderDescription { - TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() }, - }; - - var consumer = new WebConsumerOpenIdRelyingParty(serviceDescription, Global.OwnSampleOPHybridTokenManager); + var consumer = CreateConsumer(); consumer.AttachAuthorizationRequest(e.Request, "http://tempuri.org/IDataApi/GetName"); } protected async void identifierBox_LoggedIn(object sender, OpenIdEventArgs e) { State.FetchResponse = e.Response.GetExtension<FetchResponse>(); - ServiceProviderDescription serviceDescription = new ServiceProviderDescription { - AccessTokenEndpoint = new MessageReceivingEndpoint(new Uri(e.Response.Provider.Uri, "/access_token.ashx"), HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest), - TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() }, + var serviceDescription = new ServiceProviderDescription { + TokenRequestEndpoint = new Uri(e.Response.Provider.Uri, "/access_token.ashx"), }; - var consumer = new WebConsumerOpenIdRelyingParty(serviceDescription, Global.OwnSampleOPHybridTokenManager); - - AuthorizedTokenResponse accessToken = await consumer.ProcessUserAuthorizationAsync(e.Response); + var consumer = CreateConsumer(); + consumer.ServiceProvider = serviceDescription; + AccessTokenResponse accessToken = await consumer.ProcessUserAuthorizationAsync(e.Response); if (accessToken != null) { this.MultiView1.SetActiveView(this.AuthorizationGiven); @@ -58,5 +54,12 @@ protected void identifierBox_Failed(object sender, OpenIdEventArgs e) { this.MultiView1.SetActiveView(this.AuthenticationFailed); } + + private static WebConsumerOpenIdRelyingParty CreateConsumer() { + var consumer = new WebConsumerOpenIdRelyingParty(); + consumer.ConsumerKey = new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Request.ApplicationPath).AbsoluteUri; + consumer.ConsumerSecret = "some crazy secret"; + return consumer; + } } } |