thrzn41/WebexTeamsAPIClient

Examples for oAuth

Opened this issue · 1 comments

Do you have any example on how to use this API with the Cisco oAuth workflow?

I am very sorry for the late reply.

The followings may be an example.
This tool uses the OAuth grant flow to obtain Access Token.
https://github.com/thrzn41/WebexTeamsAPIClient/tree/master/CSharp/UnitTestTool.EncryptIntegrationInfo

// Create an OAuth Client.
// CLIENT_SECRET and CLIENT_ID are obtained from an integration info on Webex for Developers site.
var oauth2 = TeamsAPI.CreateVersion1OAuth2Client(
                 "CLIENT_SECRET",
                 "CLIENT_ID",
                  new TeamsRetryOnErrorHandler(4, TimeSpan.FromSeconds(15.0f)));

// CODE will be generated for an authenticated user during OAuth 2.0 grant flow.
// In the above tool, WebBrowser Control(Windows Form) is used to get CODE.
// REDIRECT_URI is one of the Redirect URIs set up for the integration on Webex for Developers site.
var r = await oauth2.GetTokenInfoAsync(
                  "CODE",
                  "REDIRECT_URI");

if(r.IsSuccessStatus)
{
    // This is token info contains AccessToken, RefreshToken and these expiration info.
    var tokenInfo = r.Data;
}

For now, this API client does not refresh Access Token automatically after expiration.
So, you need to refresh after the Token is expired(If you get HTTP 401 Unauthorized error).

// REFRESH_TOKEN is contanined in the above tokenInfo.
var r = await oauth2.RefreshTokenInfoAsync("REFRESH_TOKEN");

if(r.IsSuccessStatus)
{
    // This is token info contains new AccessToken, RefreshToken and these expiration info.
    var tokenInfo = r.Data;
}