Pregunta

Using DotNetOpenAuth, we've succesfully implemented asynchronous 2- and 3-legged authentication.

However, we are now facing a situation where we need to perform synchronous 2-legged authentication. At the moment the user presses a button to retrieve data, we need to sequentially 1) obtain a token and 2) perform the data request using this token. An asynchronous 2-legged authentication with callback would result in the retrieval failing the first time and -after the authentication is complete- succeeding when the user presses the button a second time.

In DotNetOpenAuth there is a WebServerClient, a consumer that seems to be able to retrieve an OAuth token based on a consumer Key and Secret, using a 2-legged OAuth step.

The question: Is it possible to await the result of this token retrieval?

We're looking for some code samples that explain this concept, because we cannot seem to find sample usages of the WebServerClient

¿Fue útil?

Solución

We've found the solution in the WebConsumer class after all. The way to obtain a token using a synchronous 2-legged OAuth step

OAuthGlobals.TokenManager = new InMemoryTokenManager(consumerKey, consumerSecret); 
WebConsumer consumer = new WebConsumer(OAuthGlobals.ServiceProviderDescription, OAuthGlobals.TokenManager); 
OAuthGlobals.AccessToken = consumer.RequestNewClientAccount();

The RequestNewClientAccount() performs the synchronous step.

Of course, the handler that processes this request needs to be able to process it, so we needed to adapt it for this case.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top