1515 using OAuthConsumer . SampleServiceProvider ;
1616
1717 public partial class SampleWcf2 : System . Web . UI . Page {
18- private static InMemoryClientTokenManager TokenManager = new InMemoryClientTokenManager ( ) ;
18+ private static InMemoryClientTokenManager tokenManager = new InMemoryClientTokenManager ( ) ;
1919
2020 private static IAuthorizationState Authorization {
2121 get { return ( AuthorizationState ) HttpContext . Current . Session [ "Authorization" ] ; }
@@ -44,7 +44,7 @@ where item.Selected
4444
4545 var client = CreateClient ( ) ;
4646 string clientState ;
47- var response = client . PrepareRequestUserAuthorization ( TokenManager . NewAuthorization ( scope , out clientState ) ) ;
47+ var response = client . PrepareRequestUserAuthorization ( tokenManager . NewAuthorization ( scope , out clientState ) ) ;
4848 response . ClientState = clientState ;
4949 client . Channel . Send ( response ) ;
5050 }
@@ -75,9 +75,24 @@ protected void getFavoriteSites_Click(object sender, EventArgs e) {
7575 }
7676 }
7777
78+ private static WebServerClient CreateClient ( ) {
79+ var authServerDescription = new AuthorizationServerDescription {
80+ TokenEndpoint = new Uri ( "http://localhost:65169/OAuth2.ashx/token" ) ,
81+ AuthorizationEndpoint = new Uri ( "http://localhost:65169/OAuth2.ashx/auth" ) ,
82+ } ;
83+
84+ var client = new WebServerClient ( authServerDescription ) {
85+ ClientIdentifier = "sampleconsumer" ,
86+ ClientSecret = "samplesecret" ,
87+ TokenManager = tokenManager ,
88+ } ;
89+
90+ return client ;
91+ }
92+
7893 private T CallService < T > ( Func < DataApiClient , T > predicate ) {
7994 DataApiClient client = new DataApiClient ( ) ;
80- //var serviceEndpoint = new MessageReceivingEndpoint(client.Endpoint.Address.Uri, HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest);
95+ //// var serviceEndpoint = new MessageReceivingEndpoint(client.Endpoint.Address.Uri, HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest);
8196 if ( Authorization == null ) {
8297 throw new InvalidOperationException ( "No access token!" ) ;
8398 }
@@ -93,18 +108,5 @@ private T CallService<T>(Func<DataApiClient, T> predicate) {
93108 return predicate ( client ) ;
94109 }
95110 }
96-
97- private static WebServerClient CreateClient ( ) {
98- var authServerDescription = new AuthorizationServerDescription {
99- TokenEndpoint = new Uri ( "http://localhost:65169/OAuth2.ashx/token" ) ,
100- AuthorizationEndpoint = new Uri ( "http://localhost:65169/OAuth2.ashx/auth" ) ,
101- } ;
102- var client = new WebServerClient ( authServerDescription ) {
103- ClientIdentifier = "sampleconsumer" ,
104- ClientSecret = "samplesecret" ,
105- TokenManager = TokenManager ,
106- } ;
107- return client ;
108- }
109111 }
110112}
0 commit comments