# Auth Provider

> Generate Authorisation Token to call Affinidi Services.

## Install Dependency

Package: AffinidiTdk.AuthProvider

```bash
dotnet add package AffinidiTdk.AuthProvider
```

Check the latest version on [nuget.org](https://www.nuget.org/packages/AffinidiTdk.AuthProvider) or view the source on [GitHub](https://github.com/affinidi/affinidi-tdk-dotnet/tree/main/src/Packages/AffinidiTdk.AuthProvider).

## API Endpoints

URLs required to initiate integration with Affinidi TDK.

### Token Endpoint

Endpoint to generate access token to call Affinidi Services with TDK.

```bash
https://apse1.auth.developer.affinidi.io/auth/oauth2/token
```

### API Gateway URL

Base API URL of Affinidi Services.

```bash
https://apse1.api.affinidi.io
```

## Classes and Methods

### AuthProvider API

Used to generate Project Scoped Token required for calling Affinidi services (Clients).

When initiating the AuthProvider class, provide the Token information including the public/private key information to generate the Authorisation Token required.

#### Required Parameters

- tokenId: ID of the Personal Access Token (PAT).

- privateKey: Private key string to use to sign the token.

- projectId: Project ID to generate the Token.

- passphrase: Passphrase of the Private key if configured.

Example

```csharp
using AffinidiTdk.AuthProvider;

var authProvider = new AuthProvider(new AuthProviderParams
{
// NOTE: set your variables for PAT
    TokenId = "

",
    PrivateKey = "

",
    ProjectId = "

"
    Passphrase = "

",
});
```

#### FetchProjectScopedTokenAsync

Return the generated Project Scoped Token to use for calling the Affinidi Services.

No parameters required.

Example

```csharp
using AffinidiTdk.AuthProvider;

var authProvider = new AuthProvider(new AuthProviderParams
{
    TokenId = "

",
    PrivateKey = "

",
    ProjectId = "

"
    Passphrase = "

",
});

var projectScopedToken = await authProvider.FetchProjectScopedTokenAsync();
```
