# 인터페이스 구현 기반 토큰 생성

> How to generate access tokens using an interface implementation.

VAT(Vivox 액세스 토큰) 생성 방법을 제어하려면 Vivox SDK의 `IVivoxTokenProvider` 인터페이스를 구현하는 클래스를 생성하고 이를 VivoxService에 등록합니다.

`VivoxService.Instance.SetTokenProvider`를 호출하여 IVivoxTokenProvider 구현을 등록하면 Vivox는 로그인과 같은 작업에 토큰이 필요할 때마다 구현의 `IVivoxTokenProvider.GetTokenAsync` 메서드를 호출합니다.

페이로드를 생성하는 데 필요한 정보는 오버라이드된 `IVivoxTokenProvider.GetTokenAsync` 메서드에 대한 입력으로 제공됩니다. 이 정보는 VAT를 작성할 때 사용됩니다.

여전히 서버 측 토큰 제공을 설정하고 오버라이드된 `IVivoxTokenProvider.GetTokenAsync` 메서드 내에서 토큰을 가져와야 합니다.

## 구독하기##to-subscribe

다음과 같이 `IVivoxTokenProvider` 구현을 등록한 후 사용자를 로그인해야 합니다.

```text
VivoxService.Instance.SetTokenProvider(new CustomTokenProvider());
```

> **Important:**
>
> **중요**: v16.5.0에서 구독 플로가 변경되었습니다. Unity Vivox SDK 16.5.0 이전 버전에서는 `IVivoxTokenProvider` 구현을 등록한 후 Vivox SDK를 초기화해야 합니다.

## 토큰 가져오기##fetch-the-token

일부가 비어 있더라도 오버라이드된 메서드에 제공된 모든 파라미터를 사용하여 페이로드를 생성하고 이를 보안 서버로 보내 Vivox 액세스 토큰을 생성합니다. 가장 좋은 방법은 모든 파라미터를 보내는 것입니다. 페이로드에 필요한 것만 반환됩니다. 페이로드를 `GetTokenAsync` 메서드에 대한 입력으로 사용합니다.

특정 토큰의 경우 다른 파라미터가 비어 있습니다. 예를 들어 로그인 토큰의 경우 targetUserUri와 channelUri는 비어 있습니다. 이는 예상된 동작입니다.

다음은 토큰 생성 예제입니다.

```cs
public class VoiceManager : MonoBehaviour
{
    async void Start()
    {
        // Must be done before any other Vivox action otherwise tokens will not be generated properly.
        VivoxService.Instance.SetTokenProvider(new VivoxTokenProvider());
        await UnityServices.InitializeAsync();
        await VivoxService.Instance.InitializeAsync();
    }
}

class VivoxTokenProvider : IVivoxTokenProvider
{
    public Task<string> GetTokenAsync(string issuer = null, TimeSpan? expiration = null, string targetUserUri = null, string action = null, string channelUri = null, string fromUserUri = null, string realm = null)
    {
        // Implement token fetching logic here.
        // The method parameters contain the necessary information for crafting the request payload.
        // This will be called whenever a token is needed for a Vivox action
    }
}
```

이 특정 플로에 대한 자세한 내용은 [Vivox 액세스 토큰으로 로그인](../developer-guide/vivox-unity-sdk-basics/using-vivox-access-tokens-together-with-uas)을 참고하시기 바랍니다.

서버 측 토큰 생성에 대한 자세한 내용은 [보안 서버에서 토큰 생성](./generate-token-secure-server/generate-token-secure-server-toc.md)을 참고하시기 바랍니다.
