Skip to content

3 legged OAuth using the wrapper

Greg Sochanik edited this page Mar 2, 2016 · 2 revisions

OAuth example

In order to generate an OAuth authenticated user token, you can do the following:

  • Obtain a Request Token
  • Redirect user to our OAuth authentication microsite to authenticate
  • Use request token to obtain an Access Token.

Obtain a Request Token:

var api = new ApiFactory(new ApiUri(), new AppSettingsCredentials());
var requestToken = await api.Create<OAuthRequestToken>()
    .Please();

ApiUri is a basic object that inherits from IApiUri containing the 7digital api url. e.g. https://github.com/7digital/SevenDigital.Api.Wrapper/blob/master/examples/ExampleUsage/ExampleUsage/ApiUri.cs

AppSettingsCredentials is an object inheriting from IOAuthCredentials pointing at somewhere that has access to your api key / secret. e.g:

https://github.com/7digital/SevenDigital.Api.Wrapper/blob/master/examples/ExampleUsage/ExampleUsage/AppSettingsCredentials.cs

Access granting microsite

Details of the web-page where access can be granted is here: http://developer.7digital.com/resources/133

Replace YOUR_KEY_HERE with your api key, and oauth_token / oauth_secret with the ones returned by the call to the request/token endpoint above.

Exchange authorised Request Token for Access Token:

var accessTokenTokenApi = await api.Create<OAuthAccessToken>()
    .ForUser(requestToken.Token, requestToken.Secret)
    .Please();

There is an api Request Token authentication endpoint, which requires a Premium api account to take advantage of.

Clone this wiki locally