Create an Access Token

There are several ways to create a new Access Token for use with the SDK, including via the CLI Login Commands or via the web app, which is covered in detail in the Authentication section. Below are methods for creating new Access Tokens from within the SDK either using your username and password, or following an SSO web approval flow.

Create a new Access Token using your email and password. Be sure to save the returned Access Token either by calling accessToken.SaveToFile() or by saving accessToken.Token to a custom storage system.

🚧

Not Supported with SSO

If your team is configured with SSO, you will not have a password for Catalytic and therefore cannot use this method to create Access Tokens. Instead, use the CreateWithWebApprovalFlow method, or create a new Access Token in the Catalytic Web App and copy or download it to use in your app. See Authentication for details.

Method Signature

AccessToken Create(string teamName, string email, string password, string name = null);
async Task<AccessToken> CreateAsync(string teamName, string email, string password, string name = null);

Parameters

ParameterTypeDescription
teamNamestringThe name or hostname of your Catalytic team. This will be
<your-team-name> if you sign into Catalytic at <your-team-name>.pushbot.com
emailstringThe email address you use to log in to Catalytic
passwordstringThe password you use to log in to Catalytic
namestringOptional name to apply to the new Access Token, which will be visible when managing your Access Tokens via the Catalytic Web App
returnsAccessTokenThe new Access Token

Example

/*
 * This example demonstrates creating a new Access Token using your
 * email and password
 */
using Catalytic.Sdk.Entities;

namespace Catalytic.Sdk.Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            var catalytic = new Catalytic.Sdk.CatalyticClient();
            var accessToken = catalytic.AccessTokens.Create(
                "your-team.pushbot.com",
                "your-email",
                "your-password");
            accessToken.SaveToFile("default");
            catalytic.AccessToken = accessToken;
            // You are now authenticated and ready to use the Catalytic SDK
            // The above only needs to be done once. Now that your Access Token
            // are saved as the default Access Token, you can configure the SDK
            // to use those:
            catalytic = new Catalytic.Sdk.Client(AccessToken.Default);
        }
    }
}

The CreateWithWebApprovalFlow Method

Create a new Access Token and approve it by logging into your Catalytic account. See Authentication for details.

👍

Supported for SSO teams

This method works for all teams, including those with SSO enabled

Method Signature

AccessToken CreateWithWebApprovalFlow(string teamName, string name = null);
async Task<AccessToken> CreateWithWebApprovalFlowAsync(string teamName, string name = null);

Parameters

ParameterTypeDescription
teamNamestringThe name or hostname of your Catalytic team. This will be
<your-team-name> if you sign into Catalytic at <your-team-name>.pushbot.com
namestringA descriptive name to associate with the new Access Token
returnsAccessTokenThe new Access Token, initially in the unapproved state.

Example

/*
 * This example demonstrates creating a new Access Token using the
 * web approval flow
 */
using Catalytic.Sdk.Entities;

namespace Catalytic.Sdk.Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            var catalytic = new Catalytic.Sdk.CatalyticClient();

            var accessToken = catalytic.AccessTokens.CreateWithWebApprovalFlow(
                "your-team.pushbot.com");

            var approvalUrl = catalytic.AccessTokens.GetApprovalUrl(accessToken);
            catalytic.AccessTokens.OpenUrl(approvalUrl);
            catalytic.AccessTokens.WaitForApproval(accessToken);

            accessToken.SaveToFile("default");
            catalytic.AccessToken = accessToken;

            // You are now authenticated and ready to use the Catalytic SDK
            // The above only needs to be done once. Now that your Access Token
            // is saved as the default Access Token, you can configure the SDK
            // to use those:
            catalytic = new Catalytic.Sdk.Client(AccessToken.Default);
        }
    }
}

The GetApprovalUrl Method

Gets the URL that the user must visit to approve Access Token created with CreateWithWebApprovalFlow.

Method Signature

Uri GetApprovalUrl(AccessToken accessToken, string applicationName = "Catalytic SDK");

Parameters

ParameterTypeDescription
accessTokenAccessTokenThe Access Token returned from CreateWithWebApprovalFlow()
applicationNamestringOptional name of the application requesting the token. Defaults to "Catalytic SDK"
returnsUriThe URL to direct the user to to approve the new token

Example

See the above GetApprovalUrl Example

The OpenUrl Method

Opens a URL returned from GetApprovalUrl in the OS's default browser. Currently supported OS's are OSX, Windows and Linux.

Method Signature

void OpenUrl(Uri url);

Example

See the above GetApprovalUrl Example

The WaitForApproval Method

Wait for an Access Token created with CreateWithWebApprovalFlow to be approved by the user in the Catalytic Web App. This method will complete as soon as the user logs in to their Catalytic team and approves the Access Token request. Be sure to save the returned Access Token either by calling accessToken.SaveToFile() or by saving accessToken.Token to a custom storage system.

Method Signature

AccessToken WaitForApproval(AccessToken accessToken, int? waitTimeMillis = null);
async Task<AccessToken> WaitForApprovalAsync(AccessToken accessToken, int? waitTimeMillis = null);

Parameters

ParameterTypeDescription
accessTokenAccessTokenThe Access Token returned from CreateWithWebApprovalFlow()
waitTimeMillisint?Optional number of milliseconds to wait before timing out
returnsAccessTokenThe approved Access Token

Example

See the above GetApprovalUrl Example