> For the complete documentation index, see [llms.txt](https://docs.taptalk.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.taptalk.io/onetalk-omnichannel-documentation/onetalk-channel-integration/live-chat/onetalk-ios/authentication.md).

# Authentication

TapTalk.io Omnichannel SDK provides some essential methods to handle user authentication.

### Authenticate User (Optional)

You can authenticate the user that is currently logged in before calling **`presentTapTalkLiveView`** or **`pushTapTalkLiveView`**. To do this, provide the user's full name and email by calling **`authenticateUser`** from the **TapTalkLive** class after initializing the SDK.

{% tabs %}
{% tab title="Objective-C" %}

```objective-c
// For version 3.0.0 and above
#import "OneTalkLiveChat.h"

// For versions below 3.0.0
#import <TapTalkLive/TapTalkLive.h>

[[TapTalkLive sharedInstance] authenticateUserWithFullName:NAME
                                                     email:EMAIL
success:^(NSString *message) {
    // Successfully authenticated user
}
failure:^(NSError *error) {
    // Failed to authenticate user
}];
```

{% endtab %}

{% tab title="Swift" %}

```swift
import OneTalkLiveChat

TapTalkLive.sharedInstance().authenticateUser(
    withFullName: NAME,
    email: EMAIL
) { message in
    // Successfully authenticated user
}
failure: { error in
    // Failed to authenticate user
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
**`NAME`**: (String) current user's full name\
**`EMAIL`**: (String) current user's email address
{% endhint %}

After successfully authenticated, user will no longer be required to fill name and email to create a case.

### Authenticate with Auth Ticket (Optional)

You can also authenticate using an existing auth ticket with **`requestAccessTokenWithAuthTicket`** method from the **TapTalkLive** class after initializing the SDK.

{% tabs %}
{% tab title="Objective-C" %}

```objective-c
// For version 3.0.0 and above
#import "OneTalkLiveChat.h"

// For versions below 3.0.0
#import <TapTalkLive/TapTalkLive.h>

[[TapTalkLive sharedInstance] requestAccessTokenWithAuthTicket:AUTH_TICKET
success:^(NSString *message) {
    // Successfully authenticated user
}
failure:^(NSError *error) {
    // Failed to authenticate user
}];
```

{% endtab %}

{% tab title="Swift" %}

```swift
import OneTalkLiveChat

TapTalkLive.sharedInstance().requestAccessToken(withAuthTicket: AUTH_TICKET) { message in
    // Successfully authenticated user
}
failure: { error in
    // Failed to authenticate user
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Parameters**\
**`AUTH_TICKET`**: (String) existing auth ticket retrieved from the server
{% endhint %}

### Logout

You can clear the currently authenticated user data using the **`logout`** method. After logout is finished, locally saved user and chat data will be cleared, and you may authenticate another user.

{% tabs %}
{% tab title="Objective-C" %}

```objective-c
// For version 3.0.0 and above
#import "OneTalkLiveChat.h"

// For versions below 3.0.0
#import <TapTalkLive/TapTalkLive.h>

[[TapTalkLive sharedInstance] logout:^(NSString *message) {
    // Successfully logged out
}
failure:^(NSError *error) {
    // An error occured, but local user data is still cleared
}];
```

{% endtab %}

{% tab title="Swift" %}

```swift
import OneTalkLiveChat

TapTalkLive.sharedInstance().logout { message in
    // Successfully logged out
}
failure: { error in
    // An error occured, but local user data is still cleared
}
```

{% endtab %}
{% endtabs %}

### Logout and Clear TapTalkLive Data

Call this method when you need to logout and clear all local cached data from Omnichannel SDK.

{% tabs %}
{% tab title="Objective-C" %}

```objective-c
// For version 3.0.0 and above
#import "OneTalkLiveChat.h"

// For versions below 3.0.0
#import <TapTalkLive/TapTalkLive.h>

[[TapTalkLive sharedInstance] logoutAndClearAllTapLiveData:^(NSString *message) {
    // Successfully logged out and cleared all TapTalkLive data
}
failure:^(NSError *error) {
    // An error occured, but local data is still cleared
}];
```

{% endtab %}

{% tab title="Swift" %}

```swift
import OneTalkLiveChat

TapTalkLive.sharedInstance().logoutAndClearAllTapData { message in
    // Successfully logged out and cleared all TapTalkLive data
}
failure: { error in
    // An error occured, but local data is still cleared
}
```

{% endtab %}
{% endtabs %}
