Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPC Core Kit Swift docs #699

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: "Authentication Overview in MPC Core Kit iOS SDK"
sidebar_label: "Overview"
description: "Web3Auth MPC Core Kit iOS SDK - Authentication Overview | Documentation - Web3Auth"
---

import TabItem from "@theme/TabItem";
import Tabs from "@theme/Tabs";

There are two ways to login your users, depending on the type of authentication method you've
chosen. If you are looking for an Authentication Flow in your application like
[Single Page Application(SPA)](https://www.oauth.com/oauth2-servers/single-page-apps/) flow, you can
use the `loginWithOAuth` method.

If you are looking to pass a JWT-based IdToken to the SDK from your application, like
[Regular Web Application(RWA)](https://www.oauth.com/oauth2-servers/server-side-apps/) Flow or even
using your own JWT provider, you can use the `loginWithJWT` method.

As a prerequisite, before triggering the login function, you need to create a verifier for your
login method on the [Web3Auth Dashboard](https://dashboard.web3auth.io).

## Creating a Verifier

Since this is a Core Kit SDK, it gives you flexibility to use your own authentication service. You
need to create a custom verifier, which allows you to plug in your own authentication service to
authenticate users.

For example, while authenticating with Google, you have to use your own Google Client ID setup to
authenticate users directly or use auth provider services like Auth0, Firebase, AWS Cognito etc.
Additionally, you can make your own JWT token authentication system and pass over the ID Token to
Web3Auth.

[Learn how to create a verifier](/auth-provider-setup/verifiers).

![Create a Verifier](/images/dashboard/create-verifier.gif)

## Login Methods

As discussed earlier, there are two login methods available in the SDK tailored to your use case.

- [Login with OAuth](/sdk/mpc-core-kit/mpc-core-kit-js/authentication/login-oauth): You can use this
method the implicit login flow, where you don't need to manually handle the authentication and get
the JWT token.

- [Login with JWT](/sdk/mpc-core-kit/mpc-core-kit-js/authentication/login-jwt): You can use this
method to manually handle the authentication, and send the JWT token to Web3Auth. This method
allows you to bring your own authentication flow.

:::tip Recommended

For faster login speeds, we recommend using the
[Login with JWT](/sdk/mpc-core-kit/mpc-core-kit-js/authentication/login-jwt) method.

:::
115 changes: 115 additions & 0 deletions docs/sdk/mpc-core-kit/mpc-core-kit-swift/authentication/login-jwt.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
title: "Log in with OAuth"
sidebar_label: "Log in with OAuth"
description: "Web3Auth MPC Core Kit Swift SDK - Log in with OAuth | Documentation - Web3Auth"
---

import ServiceWorkerCode from "@site/src/common/sdk/infra/tkey/_sw-js.mdx";

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

To authenticate users using Single Page Application(SPA) flow, you can use the `loginWithOAuth`
method. The SDK uses method overloading to support both single verifier and aggregate verifier.

Unlike the `loginWithJWT` method, this approach doesn't require you to manage the authentication
process manually. The method automatically manages the authentication flow and handles the response
from redirection internally.

:::info Recommended

The [loginWithJWT](/docs/sdk/mpc-core-kit/mpc-core-kit-ios/authentication/login-jwt) method is
recommended for faster login experience.

:::

## Single Verifier

A single verifier flow operates independently of the other verifiers you've created on the Web3Auth
dashboard. For example, if you've set up custom verifiers for Google and Apple on the dashboard,
each verifier will generate a different wallet for the same user.

To login with a single verifier, you will require to create a custom verifier in the Web3Auth
dashboard. If you haven't already created one,
[learn how to create a verifier](/docs/auth-provider-setup/byo-jwt-provider/#set-up-custom-jwt-verifier).

The method takes `SingleLoginParams` as a parameter.

### Parameters

| Name | Description |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `typeOfLogin` | Defines the type of social/ OAuth login you want to use. Available values are `.google`, `.facebook`, `.discord`, `.reddit`, `.twitch`, `.apple`, `.github`, `.linkedin`, `.twitter`, `.weibo`, `.line`, `.email_password`, `.email_passwordless`, `.sms_passwordless`, and `.jwt` |
| `verifier` | Your custom verifier name. |
| `clientId` | Your OAuth provider client id. For instance, if you are using `LoginType.google` it'll take the google login id. |
| `redirectURL` | Defines the redirect URL, the default value is `https://scripts.toruswallet.io/redirect.html`. |
| `jwtParams?` | Auth0 login parameters. See [Auth0ClientOptions](https://github.com/torusresearch/customauth-swift-sdk/blob/master/Sources/CustomAuth/Common/LoginParams/Auth0ClientOptions.swift). Explicitly required for login types: `.jwt`, `.email_passwordless`, `.sms_passwordless`. |
| `hash?` | This is the urlfragment part of the url, only use if needed. |

### Usage

```swift
import CustomAuth

let singleLoginParams = SingleLoginParams(
typeOfLogin: .google,
verifier: "YOUR_GOOGLE_VERIFIER_NAME",
clientId: "YOUR_GOOGLE_CLIENT_ID"
)

do {
// Use an existing MPCCoreKit instance
let result = try await mpcCoreKit.loginWithOAuth(
singleLoginParams: singleLoginParams
)
} catch {
// Handle error
}
```

## Aggregate Verifier

An aggregate verifier enables you to combine multiple verifiers/ login methods, ensuring that users
can retrieve the same wallet address regardless of the method they choose to log in.
[Learn more about aggregate verifiers](/docs/auth-provider-setup/aggregate-verifier).

To login with an aggregate verifier, you will require to create an aggregate verifier in the
Web3Auth dashboard. If you haven't already created one,
[learn how to create an aggregate verifier](/docs/auth-provider-setup/aggregate-verifier#setting-up-an-aggregate-verifier).

The method takes `AggregateLoginParams` as a parameter.

### Parameters

| Name | Description |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `aggregateVerifierType` | Defines the aggregate verifier type. Supported value is `AggregateVerifierType.single_id_verifier`. This means the aggregate verifier would consider only one verification field to aggregate the different verifiers. |
| `verifierIdentifier` | Pass your top level aggregate verifier name. |
| `subVerifierDetailsArray` | Takes in a list of sub verifiers for the aggregate login, this is a list of [SingleLoginParams](#parameters). |

### Usage

```swift
import CustomAuth

let aggregateLoginParams = AggregateLoginParams(
aggregateVerifierType: AggregateVerifierType.single_id_verifier,
verifierIdentifier: "YOUR_AGGREGATE_VERIFIER_NAME",
subVerifierDetailsArray: [
SingleLoginParams(
typeOfLogin: .google,
verifier: "YOUR_GOOGLE_SUB_VERIFIER_NAME",
clientId: "YOUR_GOOGLE_CLIENT_ID"
)
]
)

do {
// Use an existing MPCCoreKit instance
let result = try await mpcCoreKit.loginWithOAuth(
aggregateLoginParams: aggregateLoginParams
)
} catch {
// Handle error
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: "Log in with OAuth"

sidebar_label: "Log in with OAuth"
description: "Web3Auth MPC Core Kit JS SDK - Log in with OAuth | Documentation - Web3Auth"
---

import ServiceWorkerCode from "@site/src/common/sdk/infra/tkey/_sw-js.mdx";

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

To authenticate users using Single Page Application(SPA) flow, you can use the `loginWithOAuth`
method. This methods takes the `OAuthLoginParams` as a parameter, which is an object that contains
the details of the verifier, and additional authentication parameters.

## Parameters

| Parameters | Description |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `loginProvider` | Defines the login provider to be used. Supported values are `LoginProviders.google`, `LoginProviders.facebook`, `LoginProviders.twitch`, `LoginProviders.reddit`, `LoginProviders.discord`, `LoginProviders.apple`, `LoginProviders.github`, `LoginProviders.linkedin`, `LoginProviders.kakao`, `LoginProviders.twitter`, `LoginProviders.weibo`, `LoginProviders.line`, `LoginProviders.wechat`, `LoginProviders.email_password`, `LoginProviders.jwt` |
| `clientId` | Client id for respective `loginProvider`. For instance google client id, auth0 client id, and etc. |
| `verifier` | Verifier name from the Web3Auth Dashboard. |
| `jwtParams` | JWT parameters. It takes `[Stirng: Stirng]` as an input. The default value is `[:]`. |
| `redirectURL` | |
| `browserRedirectURL` | |

## Usage

```swift
let result = try await mpcCoreKit.loginWithOAuth(
loginProvider: .google,
clientId: "Your Google Client id",
verifier: "Your Custom Verifier name"
);
```

## Result

The `loginWith0Auth`returns `MpcKeyDetails` upon success, which has infomration regarding
thresholds, required factors, and etc.

<Tabs
defaultValue="table"
values={[
{ label: "Table", value: "table" },
{ label: "Class", value: "class" },
]}
>

<TabItem value="table">

| Parameter | Description |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tssPubKey` | It holds the value for the TSS PubKey in compressed form. The type of `tssPubKey` is `String`. |
| `metadataPubKey` | It holds the value for metadata PubKey which is used for interacting with metadata layer. |
| `requiredFactors` | It defines the total factors still required for SDK to be in write mode. If required factors are greater than 0, the SDK will be in read mode. You can use `inputFactor` function to input factor and refresh the instance. |
| `threshold` | Defines the threshold set by the SDK. Ideally it would be 2. |
| `total_shares` | Defines the total number of shares for user. Initially if the hashed cloud factor is set, it would be 2. |

</TabItem>

<TabItem value = "class">
```swift
public struct MpcKeyDetails : Codable {
public let tssPubKey : String
public let metadataPubKey: String
public let requiredFactors: Int32
public let threshold: UInt32
public let shareDescriptions : String
public let total_shares: UInt32
}
```
</TabItem>
</Tabs>
Loading