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

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by zed-io.
zed-io/fcl-auth-swift v0.0.1-beta
A Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices
⭐️ 3
🕓 2 years ago
iOS
.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 projsrc="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: 3
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

first beta version
2 years ago

The initial version of the flow authentication service

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