Skip to content

Commit

Permalink
Merge pull request #434 from Web3Auth/sfa-ios
Browse files Browse the repository at this point in the history
Add Single Factor Auth iOS Docs
  • Loading branch information
shahbaz17 authored Jul 19, 2023
2 parents ce23bff + e1f0a83 commit cc19f96
Show file tree
Hide file tree
Showing 71 changed files with 618 additions and 161 deletions.
10 changes: 5 additions & 5 deletions docs/auth-provider-setup/byo-jwt-providers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ var privateKey = fs.readFileSync("privateKey.pem");
// openssl rsa -in privateKey.pem -pubout -out publicKey.pem
// var publicKey = fs.readFileSync("publicKey.pem");
// https://my-authz-server/.well-known/jwks.json -> publicKey to be used in Custom Authentication as JWK Endpoint.
// Visit https://community.web3auth.io/t/how-to-create-jwks-from-pem-format/2718 to convert the public key to JWK format.
// Visit https://web3auth.io/community/t/how-to-create-jwks-from-pem-format/2718 to convert the public key to JWK format.

var token = jwt.sign(
{
Expand All @@ -129,7 +129,7 @@ console.log(token);
// Step 5. inside the vscode terminal type
// openssl rsa -in privateKey.pem -pubout -out publicKey.pem
// This is the public key used to verify the JWT. This is the key that is used to make JWKS.
// Visit https://community.web3auth.io/t/how-to-create-jwks-from-pem-format/2718 to convert the public key to JWK format.
// Visit https://web3auth.io/community/t/how-to-create-jwks-from-pem-format/2718 to convert the public key to JWK format.
// Store it in gist, public folder or somewhere else that is accessible to the public.
// like this enpoint: https://my-authz-server/.well-known/jwks.json
// Step 6. Create the JWT Verifier in Web3Auth Dashboard as per the above fields of JWT.
Expand All @@ -151,7 +151,7 @@ var privateKey = fs.readFileSync("ec-secp256k1-privateKey.pem");
// openssl ec -in ec-secp256k1-privateKey.pem -pubout -out ec-secp256k1-publicKey.pem
// var publicKey = fs.readFileSync("ec-secp256k1-publicKey.pem");
// https://my-authz-server/.well-known/jwks.json -> publicKey to be used in Custom Authentication as JWK Endpoint.
// Visit https://community.web3auth.io/t/how-to-create-jwks-from-pem-format/2718 to convert the public key to JWK format.
// Visit https://web3auth.io/community/t/how-to-create-jwks-from-pem-format/2718 to convert the public key to JWK format.

var token = jwt.sign(
{
Expand All @@ -174,7 +174,7 @@ console.log(token);
// Step 5. inside the vscode terminal type
// openssl ec -in ec-secp256k1-privateKey.pem -pubout -out ec-secp256k1-publicKey.pem
// This is the public key used to verify the JWT. This is the key that is used to make JWKS.
// Visit https://community.web3auth.io/t/how-to-create-jwks-from-pem-format/2718 to convert the public key to JWK format.
// Visit https://web3auth.io/community/t/how-to-create-jwks-from-pem-format/2718 to convert the public key to JWK format.
// Store it in gist, public folder or somewhere else that is accessible to the public.
// like this enpoint: https://my-authz-server/.well-known/jwks.json
// Step 6. Create the JWT Verifier in Web3Auth Dashboard as per the above fields of JWT.
Expand Down Expand Up @@ -425,7 +425,7 @@ If you're using `jose` or `jsonwebtoken` library, you can use the following step
- PEM encoded key: `{paste-the-publicKey-pem-file-s-content-here}`
- Click on `Convert` button.

![JWKS Convert Tool](https://community.web3auth.io/uploads/default/optimized/1X/d815cd0b533151eb54e4b1342e4f58258c1995fd_2_690x448.jpeg)
![JWKS Convert Tool](https://web3auth.io/community/uploads/default/optimized/1X/d815cd0b533151eb54e4b1342e4f58258c1995fd_2_690x448.jpeg)

4. To complete the process, you need to save the output as a `.json` file, host it on your server, and make sure it's publicly accessible.
Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/core-kit/mpc-core-kit/mpc-core-kit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ As shares to the TSS Key and/or Metadata Key may rotate, Factor Keys allow a con

- [Source Code](https://github.com/web3auth/mpc-core-kit): Web3Auth is open sourced. You can find the source code on our GitHub repository.

- [Community Portal](https://community.web3auth.io): Join our community to get support from our team and other developers.
- [Community Portal](https://web3auth.io/community): Join our community to get support from our team and other developers.

## Helper SDKs

Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/core-kit/node/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ Hence we can call this flow a semi-custodial flow.

- [Source Code](https://github.com/Web3Auth/web3auth-backend/): Web3Auth is open sourced. You can find the source code on our GitHub repository.

- [Community Portal](https://community.web3auth.io): Join our community to get support from our team and other developers.
- [Community Portal](https://web3auth.io/community): Join our community to get support from our team and other developers.
33 changes: 12 additions & 21 deletions docs/sdk/core-kit/sfa-android/sfa-android.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,27 @@ displayed_sidebar: sdk
description: "Web3Auth Core Kit Single Factor Auth Android SDK | Documentation - Web3Auth"
---

The Web3Auth [Single Factor Auth Android SDK](https://github.com/Web3Auth/single-factor-auth-android) is a client & server side library you can use
with your Android app to authenticate users using Web3Auth. For natively using the One Key flow of Web3Auth in Android, Web3Auth provides an SFA
Android SDK written in _Java_, which helps you implement the Web3Auth without redirection in a single key pair flow.
You can use the Web3Auth [Single Factor Auth Android SDK](https://github.com/Web3Auth/single-factor-auth-android) as a library for your Android app to
authenticate users through Web3Auth. The SDK is written in Kotlin and allows for native use of the One Key flow, which starts with just one share of
the key. This means that users can authenticate without redirection in a single key pair flow.

With the Web3Auth Plug and Play Android SDK, you can easily and quickly authenticate users and reconstruct their private keys. Web3Auth Plug and Play
Android SDK redirects users to a Web3Auth-hosted screen (i.e., http://app.openlogin.com). This flow is great for most use cases. Still, you may want
to customize the authentication flow to have more control over the UI and UX of the authentication process (i.e., to avoid redirection). This can be
achieved through this new Web3Auth SFA Android SDK, where now, you can use Web3Auth and avoid the redirection to openlogin hosted screens.
Using the Web3Auth SFA Android SDK, you can authenticate users and reconstruct their private keys quickly and easily. Additionally, you can use the
Web3Auth Plug and Play Android SDK to redirect users to a Web3Auth-hosted screen (http://app.openlogin.com), which is suitable for most use cases.
However, if you want more control over the UI and UX of the authentication process, you can customize the authentication flow to avoid redirection.
This is possible with the new Web3Auth SFA Android SDK, which allows you to use Web3Auth SFA Android and prevent redirection to openlogin hosted
screens.

:::info This SDK gives you semi custodial keys
## Latest SDK Version

The `Web3Auth Plug and Play Android SDK` gives you the most straightforward flow for onboarding a user with Web3Auth. The user needs to click on the
login button, connect to their favorite social account (OAuth) or any passwordless flow, like email passwordless, biometric authentication, etc., and
a private key is generated for them. This flow has a 1/1 Key Share setup, and the whole key via Web3Auth Auth Network key shares is provided directly
to your app and reconstructed within it.

This flow is still non-custodial since the nodes in the Web3Auth network have a 5/9 consensus mechanism to generate the key shares. However, one can
claim that this flow is custodial to the OAuth Login provider since this is directly generated using credentials provided by them.

Hence, we call this flow a semi-custodial flow.

:::
- `0.0.4`

## Requirements

- Android API version `24` or newer.

## Resources

- [Quick Start](/examples?product=Core+Kit&sdk=Single+Factor+Auth+Android+SDK): Integrate Web3Auth in 4 Simple Steps.
- [Quick Start](/quick-start?product=Core+Kit&sdk=Single+Factor+Auth+Android+SDK): Integrate Web3Auth in 4 Simple Steps.

- [Example Applications](/examples?product=Core+Kit&sdk=Single+Factor+Auth+Android+SDK): Explore our example applications and try the SDK yourself.

Expand All @@ -42,4 +33,4 @@ Hence, we call this flow a semi-custodial flow.
- [Source Code](https://github.com/Web3Auth/single-factor-auth-android): Web3Auth is open sourced. You can find the source code on our GitHub
repository.

- [Community Portal](https://community.web3auth.io): Join our community to get support from our team and other developers.
- [Community Portal](https://web3auth.io/community): Join our community to get support from our team and other developers.
104 changes: 104 additions & 0 deletions docs/sdk/core-kit/sfa-ios/authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: "Authentication in Core Kit SFA iOS SDK"
sidebar_label: "Authentication"
displayed_sidebar: sdk
description: "Web3Auth Core Kit Single Factor Auth iOS SDK - Authentication | Documentation - Web3Auth"
---

Let's look at the general authentication flow at Web3Auth.

When a user logs in with Web3Auth, a user's account can be in two states:

- **Account Without MFA**: When the User logs in with only social login and key is secured by Web3Auth network.
- **Account With MFA**: When the User enables MFA by adding other shares like password, backup share, device share, etc., to their existing account.

:::warning warning

Web3Auth's SFA iOS SDK only works for those users who have **not enabled MFA**.

:::

### Without Openlogin Redirection Flow

By default, the Web3Auth SDKs use a redirection approach to reconstruct the key in both states, which involves redirecting the user to
`http://app.openlogin.com`, where all the computation required for the key reconstruction takes place. This approach simplifies the integration
process of Web3Auth SDK for applications since they don't have to worry about the key reconstruction process. However, in some cases, applications may
prefer to reconstruct the key within their own application context, allowing them to use the authentication flow described in Web3Auth's SFA Android
SDK.

## Create Custom Verifer

Once you click on the `Create Verifier` button on Web3Auth Dashboard, you'll see a toggle similar to this:

![Custom JWT Provider on Web3Auth Dashboard](/dashboard/verifiers/custom-jwt-verifier.png)

To create a custom verifier for your JWT Providers, you'll need

1. **JWT Verifier ID**

JWT Verifier ID is the unique identifier to publicly represent a user on a verifier.

e.g: sub, email, or even a custom field of your JWT etc.

> This is the `VeriferId` that is passed in the `LoginParams` of Web3Auth Single Factor Auth Android SDK.
2. **JWK Endpoint**

An endpoint containing the JWKS used for signing.

> Output of jwk endpoint should contain same fields as the example given below.
```json
{
"keys": [
{
"kty": "RSA",
"e": "AQAB",
"use": "sig",
"kid": "1bb9605c36e98e30117a69517569386830202b2d",
"n": "pAbfKmQ1ljT6yZcrdxaJxqsB7EupbBFcCLiMzmuFQMuk3y_g-vVPR8ZwTJbalwBxD-vUPmxmZAVok_iNthw1mnW0POg3kEwtl1qambgNKlaTeO8S3D-KGlUNV6bU-JXbyquds7v8bQjmIQ5oXhwIQt6x55bEyZTOCQDl3ZHy1XxeBWFyiPUXXnqkO51EFeVNiMi8Ihue16UY_lIizhivl2C_UwJ0Ymx9eWJ-nefPBo7Lr_fIxh81NaLMB6t5L8123RSIaaIcR_r1H_ZbEe9VNTfnGdYS3A0u-pNS_bm5jRSBo1qt01OFu0xEsjcO7-NESTBr8w8SUqGK86tg9oQz5w",
"alg": "RS256"
},
{
"kty": "RSA",
"e": "AQAB",
"alg": "RS256",
"kid": "c53624af1600da79f31f0314f205d4f37ad6e246",
"use": "sig",
"n": "sinuWOLB7u0NoJ5Cy92AUqC7clH0ErjTjrI_b_dBbndg0rrFZryKfbvH4ncZW_yQ9izl2mjLsjsBzVwAyzWIn83QRhTtisdV7k9AkhSGdNu-cG_qPkedhqFPIn_uyBnVpxksp8clMRALetdHncUqcTfhIpngQp_JxFHle0fNsylU510fH-iZfphLO9mMpq6eB5QGynttgpdsLxLuXe1CffNQya0pmtLkU4ATfVdXV_bMqzRxxbDOnzIaLjzUJdsMuScCTjQX93xdfzEu-Vk6zOpdkrBRUuopgAX1e8NPQz150XEOTInkh0Mfhw0t1GeB7zbbjYJDmCgYTIW1g4teBw"
}
]
}
```

3. **JWT Validations**

:::caution

- Your JWT token header must contain the `kid` field and the payload data must contain `iat` field.

:::

You can add up to 3 validation fields, including any claims like `aud`, `sub`, `iss`, `email_verified` etc. These are the claims against which a
JWT is validated.

Here are a couple of examples to be used in validation:

- Token Audience ( `aud` ):

The "aud" (audience) claim identifies the recipients for which the JWT is intended. Each principal intended to process the JWT MUST identify
itself with a value in the audience claim. If the principal processing the claim does not identify itself with a value in the "aud" claim when
this claim is present, then the JWT will be rejected. The `aud` value is a case-sensitive string containing a StringOrURI value. The
interpretation of audience values is generally application specific.

- Token Issuer ( `iss` ):

The issuing authority of the token. The `iss` value is a case-sensitive string containing a StringOrURI value. Use of this claim is OPTIONAL.

- Token Subject ( `sub` ):

The subject of the token. The `sub` value is a case-sensitive string containing a StringOrURI value. Use of this claim is OPTIONAL.

- Token Email Verified ( `email_verified` ):

The email verified claim is a boolean value that indicates whether the email address has been verified.
62 changes: 62 additions & 0 deletions docs/sdk/core-kit/sfa-ios/initialize.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: Initializing SFA iOS SDK
sidebar_label: Initialize
displayed_sidebar: sdk
description: "Web3Auth SFA iOS SDK - Initialization | Documentation - Web3Auth"
---

After Installation, the next step to use Web3Auth is to Initialize the SDK. However, the Initialization can be done in 2 ways,

- [With `Web3Auth.plist`](#with-web3authplist)
- [Without `Web3Auth.plist`](#without-web3authplist)

Please note that these are the most critical steps where you need to pass on different parameters according to the preference of your project.

## With `SingleFactorAuth.plist`

### Setup `SingleFactorAuth.plist`

In your application bundle add a plist file named `Web3Auth.plist` with the following information:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ClientId</key>
<string>YOUR_WEB3AUTH_CLIENT_ID</string>
<key>Network</key>
<string>mainnet | testnet | cyan | aqua</string>
</dict>
</plist>
```

When you have a SingleFactorAuth.plist and you have specified your Web3Auth configuration there, you can simply construct your Web3Auth instance with

```swift
import SingleFactorAuth

let singleFactorAuthArgs = SingleFactorAuthArgs(network: TorusNetwork.TESTNET)
let singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs)
```

## Without `Web3Auth.plist`

If you don't have a Web3Auth.plist or want to use optional configurtion parameters, you can construct the Web3Auth instance with

```swift
import SingleFactorAuth

let singleFactorAuthArgs = SingleFactorAuthArgs(network: TorusNetwork.TESTNET)
let singleFactoreAuth = SingleFactorAuth(singleFactorAuthArgs: singleFactorAuthArgs)
```

### `SingleFactorAuthArgs`

The `singleFactoreAuth` constructor takes an object called `SingleFactorAuthArgs` as input. The below are the aviliable fields of the
`SingleFactorAuthArgs` object.

| Parameter | Type | Mandatory | Description |
| ------------ | ------------ | --------- | ----------------------------------------------------------------------------------------------- |
| `network` | TorusNetwork | Yes | Web3Auth Network to run the authentication on, either `.MAINNET`,`.CYAN`, `.AQUA` or `.TESTNET` |
| `networkUrl` | string | No | Custom network url |
24 changes: 24 additions & 0 deletions docs/sdk/core-kit/sfa-ios/install.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: "Installing SFA iOS SDK"
sidebar_label: "Install"
displayed_sidebar: sdk
description: "Installing Web3Auth SFA iOS SDK | Documentation - Web3Auth"
---

## Cocoapods

```sh
pod install SingleFactorAuth
```

## Swift Package Manager

If you are using the Swift Package Manager, open the following menu item in Xcode:

`File > Swift Packages > Add Package Dependency`

In the Choose Package Repository prompt add this url: `https://github.com/Web3Auth/single-factor-auth-swift`

## Configuration

In order to use Web3Auth SFA you need to provide your Web3Auth `Network` to run it.
35 changes: 35 additions & 0 deletions docs/sdk/core-kit/sfa-ios/sfa-ios.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: "Web3Auth Core Kit Single Factor Auth iOS SDK"
displayed_sidebar: sdk
description: "Web3Auth Core Kit Single Factor Auth iOS SDK | Documentation - Web3Auth"
---

You can use the Web3Auth [Single Factor Auth iOS SDK](https://github.com/Web3Auth/single-factor-auth-swift) as a library for your iOS app to
authenticate users through Web3Auth. The SDK is written in Swift and allows for native use of the One Key flow, which starts with just one share of
the key. This means that users can authenticate without redirection in a single key pair flow.

Using the Web3Auth SFA iOS SDK, you can authenticate users and reconstruct their private keys quickly and easily. Additionally, you can use the
Web3Auth Plug and Play iOS SDK to redirect users to a Web3Auth-hosted screen (http://app.openlogin.com), which is suitable for most use cases.
However, if you want more control over the UI and UX of the authentication process, you can customize the authentication flow to avoid redirection.
This is possible with the new Web3Auth SFA iOS SDK, which allows you to use Web3Auth SFA iOS and prevent redirection to openlogin hosted screens.

## Latest SDK Version

- `2.0.2`

### Requirements

- iOS 14+

## Resources

- [Quick Start](/quick-start?product=Core+Kit&sdk=Single+Factor+Auth+iOS+SDK): Integrate Web3Auth in 4 Simple Steps.

- [Example Applications](/examples?product=Core+Kit&sdk=Single+Factor+Auth+iOS+SDK): Explore our example applications and try the SDK yourself.

- [Troubleshooting](/troubleshooting): Find quick solutions to common issues faced by developers.

- [Source Code](https://github.com/Web3Auth/single-factor-auth-swift): Web3Auth is open sourced. You can find the source code on our GitHub
repository.

- [Community Portal](https://web3auth.io/community): Join our community to get support from our team and other developers.
Loading

1 comment on commit cc19f96

@vercel
Copy link

@vercel vercel bot commented on cc19f96 Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web3auth-docs – ./

web3auth-docs-web3auth.vercel.app
w3a-docs.vercel.app
web3auth-docs-git-master-web3auth.vercel.app

Please sign in to comment.