# Auth Provider

> Generate Authorisation Token to call Affinidi Services.

## Install Dependency

Package: affinidi_tdk_auth_provider

```bash
pip install affinidi_tdk_auth_provider
```

Check the latest version on the [PyPI repository](https://pypi.org/project/affinidi_tdk_auth_provider/) or view the source on [GitHub](https://github.com/affinidi/affinidi-tdk/tree/main/packages/jsii/auth-provider). The Python package for auth-provider is transpiled from the TypeScript version using JSII.

## 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.

#### AuthProvider (constructor)

Initialises the AuthProvider with the Personal Access Token credentials required to generate authorisation tokens.

Parameters

    tokenId
    str
    Required
  ID of the Personal Access Token (PAT).

    privateKey
    str
    Required
  Private key string used to sign the token.

    passphrase
    str
    Optional
  Passphrase for the private key, if one is configured.

    projectId
    str
    Required
  ID of the project for which to generate the token.

Example

```python
import affinidi_tdk_auth_provider

stats = {
    'tokenId': tokenId,
    'passphrase': passphrase,
    'privateKey': privateKey,
    'projectId': projectId,
}

authProvider = affinidi_tdk_auth_provider.AuthProvider(stats)
```

#### fetch_project_scoped_token

Returns the generated project-scoped token for calling Affinidi services.

No parameters required.

Example

```python
import affinidi_tdk_auth_provider

stats = {
    'tokenId': tokenId,
    'passphrase': passphrase,
    'privateKey': privateKey,
    'projectId': projectId,
}

authProvider = affinidi_tdk_auth_provider.AuthProvider(stats)
projectScopedToken = authProvider.fetch_project_scoped_token()
```

#### create_iota_token

Creates an Affinidi Iota Framework token to generate Iota Credentials for signing the request token.

Parameters

    iotaConfigId
    str
    Required
  ID of the Iota configuration.

    did
    str
    Required
  DID of the logged-in user, obtained from the ID token provided by [Affinidi Login](/products/affinidi-elements/affinidi-login/how-affinidi-login-works.md).

    iotaSessionId
    str
    Optional
  ID of the initialised Iota session.

Example

```python
import affinidi_tdk_auth_provider

stats = {
    'tokenId': tokenId,
    'passphrase': passphrase,
    'privateKey': privateKey,
    'projectId': projectId,
}

authProvider = affinidi_tdk_auth_provider.AuthProvider(stats)
iota_token = authProvider.create_iota_token('', '')
```
