diff options
Diffstat (limited to 'samples/OAuthConsumer/SampleWcf2.aspx.cs')
-rw-r--r-- | samples/OAuthConsumer/SampleWcf2.aspx.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/samples/OAuthConsumer/SampleWcf2.aspx.cs b/samples/OAuthConsumer/SampleWcf2.aspx.cs new file mode 100644 index 0000000..2361d36 --- /dev/null +++ b/samples/OAuthConsumer/SampleWcf2.aspx.cs @@ -0,0 +1,48 @@ +using DotNetOpenAuth.OAuthWrap; + +namespace OAuthConsumer { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Web; + using System.Web.UI; + using System.Web.UI.WebControls; + + public partial class SampleWcf2 : System.Web.UI.Page { + protected void Page_Load(object sender, EventArgs e) { + if (!IsPostBack) + { + var client = CreateClient(); + var authorization = client.ProcessUserAuthorization(); + if (authorization != null) + { + Response.Write("Obtained access token: " + authorization.AccessToken); + } + } + } + + protected void getAuthorizationButton_Click(object sender, EventArgs e) { + var client = CreateClient(); + var response = client.PrepareRequestUserAuthorization(); + + string[] scopes = (from item in this.scopeList.Items.OfType<ListItem>() + where item.Selected + select item.Value).ToArray(); + response.Scope = string.Join("|", scopes); + client.Channel.Send(response); + } + + private static WebAppClient CreateClient() { + var authServerDescription = new AuthorizationServerDescription { + TokenEndpoint = new Uri("http://localhost:65169/OAuth2.ashx/token"), + AuthorizationEndpoint = new Uri("http://localhost:65169/OAuth2.ashx/auth"), + }; + var client = new WebAppClient(authServerDescription) + { + ClientIdentifier = "sampleconsumer", + ClientSecret = "samplesecret", + }; + return client; + } + } +}
\ No newline at end of file |