Swiftpack.co - zed-io/fcl-auth-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
zed-io/fcl-auth-swift
A Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices
.package(url: "https://github.com/zed-io/fcl-auth-swift.git", from: "v0.0.1-beta")

FCLAuthSwift

FCLAuthSwift is a Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices.

Demo

The demo app in this<img style="max-width:100%;" src="https://raw.github.com/zed-io/fcl-auth-swift/main/hows how to use FCL inside an iOS app.

Installation

dependencies: [
  .package(url: "https://github.com/zed-io/fcl-auth-swift.git", from: "0.0.6-beta")
]

Configuration

You will need to configure your app information before using the authentication library.

FCLAuthSwift ships with several built-in wallet providers (Dapper, Blocto), but you can also define custom wallet providers if needed.

import FCLAuthSwift

// optional: define a custom wallet provider
let provider = FCLWalletProvider(
    id: "foo",
    name: "bar",
    method: .httpPost,
    endpoint: URL(string: "https://foo.com/api/")!
)
        
fcl.config(
    appInfo: FCLAppInfo(
        title: "FCL iOS Demo",
        icon: URL(string: "https://foo.com/bar.png")!
    ),
    // default providers are [.dapper, .blocto]
    providers: [.dapper, .blocto, .custom(provider)]
)

Authenticate

fcl.authenticate(provider: .dapper) { result in
    switch result {
    case let .success(data):
        print(data.address)
    case let .failure(error):
        print(error)
    }
}

The data variable is of type FCLAuthnResponse, which contains the user's wallet address:

public struct FCLAuthnResponse {
    public let address: String
}

Delegate

The authentication library has an optional delegate to handle custom events or settings.

fcl.delegate = self

public protocol FCLAuthDelegate {
    // Show loading while waiting for network response
    func showLoading()
    // Hide loading when API call is completed 
    func hideLoading()
}

extension FCLAuthDelegate {
    // Configure which place to show authentication webview
    // The default value is ASPresentationAnchor()
    func presentationAnchor() -> UIWindow {
        return ASPresentationAnchor()
    }
}

GitHub

link
Stars: 2
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

first beta version
4 weeks ago

The initial version of the flow authentication service

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics