# 类 Authentication 子系统

> Reference the Authentication Subsystem class for handling connections to Unity Authentication.

用于处理 Unity Authentication 系统连接的子系统。

##### Include（包括）##include

```cpp
#include "AuthenticationSubsystem.h"
```

##### 语法##syntax

```cpp
UCLASS()
class AUTHENTICATION_API UAuthenticationSubsystem : public UGameInstanceSubsystem
```

## 构造函数##constructors

### UAuthenticationSubsystem()##uauthenticationsubsystem()

Authentication 子系统的默认构造函数。

#### 声明##declaration

```cpp
UAuthenticationSubsystem()
```

### UAuthenticationSubsystem(FVTableHelper&)##uauthenticationsubsystem(fvtablehelper&)

用于前向声明的覆盖构造函数。

#### 声明##declaration

```cpp
UAuthenticationSubsystem(FVTableHelper& Helper)
```

#### 参数##parameters

| **Name** | **描述**             |
| :------- | :----------------- |
| Helper   | 用于调用专用热重载构造函数的辅助类。 |

## 析构函数##destructors

### UAuthenticationSubsystem()##uauthenticationsubsystem()

Authentication 子系统的默认析构函数。

#### 声明##declaration

```cpp
virtual ~UAuthenticationSubsystem()
```

## 覆盖##overrides

### Initialize(FSubsystemCollectionBase&)##initialize(fsubsystemcollectionbase&)

初始化 USubsystem 的覆盖。

#### 声明##declaration

```cpp
virtual void Initialize(FSubsystemCollectionBase& Collection) override
```

### Deinitialize()##deinitialize()

初始化 USubsystem 的覆盖。

#### 声明##declaration

```cpp
virtual void Deinitialize() override
```

### ShouldCreateSubsystem(UObject\*)##shouldcreatesubsystem(uobject\*)

初始化 USubsystem 的覆盖。

#### 声明##declaration

```cpp
virtual bool ShouldCreateSubsystem(UObject* Outer) const override
```

## 方法##methods

### SignInAnonymously(FAuthenticationSignInOptions, Unity::Services::Core::THandler\<FAuthenticationResponse>)##signinanonymously(fauthenticationsigninoptions,-unity::services::core::thandlerfauthenticationresponse)

匿名登录当前用户。不需要任何凭据，并且会话仅限于当前设备。

#### 声明##declaration

```cpp
void SignInAnonymously(FAuthenticationSignInOptions Options, Unity::Services::Core::THandler<FAuthenticationResponse> ResponseHandler)
```

#### 参数##parameters

| **Name**          | **类型**                                                                                                                         | **描述**                |
| :---------------- | :----------------------------------------------------------------------------------------------------------------------------- | :-------------------- |
| `Options`         | [FAuthenticationSignInOptions](./models/authentication-sign-in-options.md)                                                     | 登录选项。                 |
| `ResponseHandler` | [THandler](../services-core/utils/services-utils#thandler)`<`[FAuthenticationResponse](./models/authentication-response.md)`>` | 当 API 返回一个响应时执行的处理程序。 |

### GetUserInfo(Unity::Services::Core::THandler\<FAuthenticationUserResponse>)##getuserinfo(unity::services::core::thandlerfauthenticationuserresponse)

返回当前玩家的玩家信息，例如帐户创建时间和关联的外部 ID。

#### 声明##declaration

```cpp
void GetUserInfo(Unity::Services::Core::THandler<FAuthenticationUserResponse> ResponseHandler)
```

#### 参数##parameters

| **Name**          | **类型**                                                                                                                                                                 | **描述**                |
| :---------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------- |
| `ResponseHandler` | [THandler](/authentication-unreal/sdk-api/services-core/utils/services-utils.md#thandler)`<`[FAuthenticationUserResponse](./models/authentication-user-response.md)`>` | 当 API 返回一个响应时执行的处理程序。 |

### DeleteUser(Unity::Services::Core::THandler\<bool>)##deleteuser(unity::services::core::thandlerbool)

永久删除当前登录的用户。

#### 声明##declaration

```cpp
void DeleteUser(Unity::Services::Core::THandler<bool> ResponseHandler)
```

#### 参数##parameters

| **Name**          | **类型**                                                                                            | **描述**                |
| :---------------- | :------------------------------------------------------------------------------------------------ | :-------------------- |
| `ResponseHandler` | [THandler](/authentication-unreal/sdk-api/services-core/utils/services-utils.md#thandler)`<bool>` | 当 API 返回一个响应时执行的处理程序。 |

### RegisterStateChangedCallback(Unity::Services::Core::THandler\<FAuthenticationStateChangedResponse>)##registerstatechangedcallback(unity::services::core::thandlerfauthenticationstatechangedresponse)

挂接到在身份验证状态更改时执行的委托。

#### 声明##declaration

```cpp
void RegisterStateChangedCallback(Unity::Services::Core::THandler<FAuthenticationStateChangedResponse> ResponseHandler)
```

#### 参数##parameters

| **Name**          | **类型**                                                                                                                                                                                  | **描述**             |
| :---------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------- |
| `ResponseHandler` | [THandler](/authentication-unreal/sdk-api/services-core/utils/services-utils.md#thandler)`<`[FAuthenticationStateChangedResponse](./models/authentication-state-changed-response.md)`>` | 在身份验证状态更改时执行的处理程序。 |

### SignOut(bool)##signout(bool)

在提供的配置文件名称下注销当前用户。

#### 声明##declaration

```cpp
bool SignOut(bool bClearCredentials = false)
```

#### 参数##parameters

| **Name**            | **类型** | **描述**              |
| :------------------ | :----- | :------------------ |
| `bClearCredentials` | `bool` | 清除用于登录同一帐户的会话令牌的选项。 |

### SwitchProfile(const FString&)##switchprofile(const-fstring&)

将当前配置文件切换为新的配置文件名称。如果在该名称下未找到配置文件，则会创建新的配置文件。

#### 声明##declaration

```cpp
void SwitchProfile(const FString& ProfileName) const
```

#### 参数##parameters

| **参数名称**      | **参数类型**                                                                                | **描述**                       |
| :------------ | :-------------------------------------------------------------------------------------- | :--------------------------- |
| `ProfileName` | [FString](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Containers/FString/) | 要切换到的配置文件的名称，如果尚不存在，则会添加该名称。 |

### ProfileExists(const FString&)##profileexists(const-fstring&)

检查配置文件是否存在。

#### 声明##declaration

```cpp
const bool ProfileExists(const FString& ProfileName) const
```

#### 参数##parameters

| **Name**      | **类型**                                                                                  | **描述**       |
| :------------ | :-------------------------------------------------------------------------------------- | :----------- |
| `ProfileName` | [FString](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Containers/FString/) | 要检查的配置文件的名称。 |

#### 返回##returns

| **类型** | **描述**                     |
| :----- | :------------------------- |
| `bool` | 如果配置文件存在，为 true，否则为 false。 |

### GetCurrentProfileName()##getcurrentprofilename()

返回当前配置文件的名称。

#### 声明##declaration

```cpp
const FString GetCurrentProfileName() const
```

#### 返回##returns

| **类型**                                                                                  | **描述**     |
| :-------------------------------------------------------------------------------------- | :--------- |
| [FString](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Containers/FString/) | 当前配置文件的名称。 |

### GetProfileNames()##getprofilenames()

返回所有活跃玩家配置文件名称。

#### 声明##declaration

```cpp
const TArray<FString> GetProfileNames() const
```

#### 返回##returns

| **类型**                                                                                                                                                                                | **描述**        |
| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------ |
| [TArray](https://docs.unrealengine.com/5.3/en-US/array-containers-in-unreal-engine/#tarray)\<[FString](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Containers/FString/)> | 所有活跃玩家配置文件名称。 |

### RegisterProfileChangedCallback(Unity::Services::Core::THandler\<FAuthenticationPlayerProfileChangedResponse>)##registerprofilechangedcallback(unity::services::core::thandlerfauthenticationplayerprofilechangedresponse)

挂接到在玩家配置文件更改时执行的处理程序。

#### 声明##declaration

```cpp
void RegisterProfileChangedCallback(Unity::Services::Core::THandler<FAuthenticationPlayerProfileChangedResponse> ResponseHandler)
```

#### 参数##parameters

| **Name**          | **类型**                                                                                                                                                                                                   | **描述**             |
| :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------- |
| `ResponseHandler` | [THandler](/authentication-unreal/sdk-api/services-core/utils/services-utils.md#thandler)`<`[FAuthenticationPlayerProfileChangedResponse](./models/authentication-player-profile-changed-response.md)`>` | 在玩家配置文件更改时执行的处理程序。 |

### RegisterProfileDeletedCallback(Unity::Services::Core::THandler\<FAuthenticationPlayerProfileDeletedResponse> ResponseHandler)##registerprofiledeletedcallback(unity::services::core::thandlerfauthenticationplayerprofiledeletedresponse-responsehandler)

挂接到在玩家配置文件被删除时执行的处理程序。

#### 声明##declaration

```cpp
void RegisterProfileDeletedCallback(Unity::Services::Core::THandler<FAuthenticationPlayerProfileDeletedResponse> ResponseHandler)
```

#### 参数##parameters

| **Name**          | **类型**                                                                                                                                                                                                   | **描述**              |
| :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------ |
| `ResponseHandler` | [THandler](/authentication-unreal/sdk-api/services-core/utils/services-utils.md#thandler)`<`[FAuthenticationPlayerProfileDeletedResponse](./models/authentication-player-profile-deleted-response.md)`>` | 在玩家配置文件被删除时执行的处理程序。 |

### IsSignedIn()##issignedin()

检查用户是否已登录。

> **Note:**
>
> 用户可以保持登录但会话已到期。

#### 声明##declaration

```cpp
bool IsSignedIn() const
```

#### 返回##returns

| **类型** | **描述**                    |
| :----- | :------------------------ |
| `bool` | 如果用户已登录，为 true，否则为 false。 |

### IsAnonymous()##isanonymous()

检查用户是否匿名登录。

#### 声明##declaration

```cpp
bool IsAnonymous() const
```

#### 返回##returns

| **类型** | **描述**                     |
| :----- | :------------------------- |
| `bool` | 如果用户匿名登录，为 true，否则为 false。 |

### IsAuthorized()##isauthorized()

检查用户是否仍然被授权。

> **Note:**
>
> 只要用户的访问令牌仍然有效，用户就仍然被授权。

#### 声明##declaration

```cpp
bool IsAuthorized() const
```

#### 返回##returns

| **类型** | **描述**                    |
| :----- | :------------------------ |
| `bool` | 如果用户被授权，为 true，否则为 false。 |

### IsExpired()##isexpired()

检查用户会话是否到期。

#### 声明##declaration

```cpp
bool IsExpired() const
```

#### 返回##returns

| **类型** | **描述**                      |
| :----- | :-------------------------- |
| `bool` | 如果用户会话已到期，为 true，否则为 false。 |

### SessionTokenExists()##sessiontokenexists()

检查是否为当前配置文件存储了现有会话令牌。

#### 声明##declaration

```cpp
bool SessionTokenExists() const
```

#### 返回##returns

| **类型** | **描述**                      |
| :----- | :-------------------------- |
| `bool` | 如果为当前配置文件存储了现有会话令牌，则为 true。 |

### GetUnityProjectId()##getunityprojectid()

返回 Unity Project ID。

#### 声明##declaration

```cpp
const FGuid GetUnityProjectId() const
```

#### 返回##returns

| **类型**                                                                        | **描述**            |
| :---------------------------------------------------------------------------- | :---------------- |
| [FGuid](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Misc/FGuid/) | Unity Project ID。 |

### GetUnityEnvironmentName()##getunityenvironmentname()

返回 Unity 环境名称。

#### 声明##declaration

```cpp
const FString GetUnityEnvironmentName() const
```

#### 返回##returns

| **类型**                                                                                  | **描述**      |
| :-------------------------------------------------------------------------------------- | :---------- |
| [FString](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Containers/FString/) | Unity 环境名称。 |

### GetAccessToken()##getaccesstoken()

返回当前用户的访问令牌。

#### 声明##declaration

```cpp
FString GetAccessToken() const
```

#### 返回##returns

| **类型**                                                                                  | **描述**                           |
| :-------------------------------------------------------------------------------------- | :------------------------------- |
| [FString](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Containers/FString/) | 如果当前用户已登录，为当前用户的访问令牌字符串，否则为空字符串。 |

### GetSessionToken()##getsessiontoken()

返回当前用户的会话令牌。

#### 声明##declaration

```cpp
const const FString GetSessionToken() const
```

#### 返回##returns

| **类型**                                                                                  | **描述**                           |
| :-------------------------------------------------------------------------------------- | :------------------------------- |
| [FString](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Containers/FString/) | 如果当前用户已登录，为当前用户的会话令牌字符串，否则为空字符串。 |

### GetUserId()##getuserid()

当前登录用户的 ID。

#### 声明##declaration

```cpp
const FString GetUserId() const
```

#### 返回##returns

| **类型**                                                                                  | **描述**                       |
| :-------------------------------------------------------------------------------------- | :--------------------------- |
| [FString](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Containers/FString/) | 如果当前用户已登录，为当前用户的 ID，否则为空字符串。 |

### GetState()##getstate()

Authentication 子系统的当前状态。

#### 声明##declaration

```cpp
const EAuthenticationStates GetState() const
```

#### 返回##returns

| **类型**                                              | **描述**                   |
| :-------------------------------------------------- | :----------------------- |
| [EAuthenticationStates](./authentication-states.md) | Authentication 子系统的当前状态。 |

### SetUnityProjectId(FGuid)##setunityprojectid(fguid)

设置 Unity Project ID。

#### 声明##declaration

```cpp
void SetUnityProjectId(FGuid Value)
```

#### 参数##parameters

| **Name** | **类型**                                                                        | **描述**               |
| :------- | :---------------------------------------------------------------------------- | :------------------- |
| 值        | [FGuid](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Misc/FGuid/) | 新的 Unity Project ID。 |

### SetUnityEnvironmentName(FString)##setunityenvironmentname(fstring)

设置 Unity 环境名称。

#### 声明##declaration

```cpp
void SetUnityEnvironmentName(FString Value)
```

#### 参数##parameters

| **Name** | **类型**                                                                                  | **描述**          |
| :------- | :-------------------------------------------------------------------------------------- | :-------------- |
| 值        | [FString](https://docs.unrealengine.com/5.3/en-US/API/Runtime/Core/Containers/FString/) | 新的 Unity 环境 ID。 |
