speziaccessguard

Spezi Module to Protect Views with an Access Code or Biometrics Authentication

https://github.com/stanfordspezi/speziaccessguard

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    1 of 6 committers (16.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.0%) to scientific vocabulary

Keywords from Contributors

chatbot large-language-models spezi swiftui stanford xcode digital-health digitalhealth fhir
Last synced: 6 months ago · JSON representation ·

Repository

Spezi Module to Protect Views with an Access Code or Biometrics Authentication

Basic Info
Statistics
  • Stars: 5
  • Watchers: 8
  • Forks: 3
  • Open Issues: 6
  • Releases: 10
Created over 2 years ago · Last pushed 10 months ago
Metadata Files
Readme License Citation

README.md

Spezi Access Guard

Build and Test codecov DOI

Allows developers to easily guard a SwiftUI view with an access code or biometrics.

|Screenshot showing access guarded to a SwiftUI view by an access code.|Screenshot showing access guarded to a SwiftUI view by Face ID with an access code fallback.| |:--:|:--:| |4-digit Numeric Access Code|Face ID with Access Code Fallback|

Overview

The Access Guard module allows developers to guard a SwiftUI view with an access code or biometrics and allows users to set or reset their access codes.

For more information, please refer to the API documentation.

Setup

1. Add Spezi Access Guard as a Dependency

First, you will need to add the SpeziAccessGuard Swift package to your app in Xcode or Swift package.

2. Register the Access Guard Module

[!IMPORTANT] If your application is not yet configured to use Spezi, follow the Spezi setup article to set up the core Spezi infrastructure.

You can configure the AccessGuardModule in the SpeziAppDelegate as follows.

Access Code

In the example below, we configure the AccessGuardModule with one access guard that uses an access code and is identified by ExampleIdentifier. The codeOptions property defines the type of code used, which in this case is a 4-digit numeric code. The timeout property defines when the view should be locked based on the time the scene is not in the foreground, in seconds.

```swift import Spezi import SpeziAccessGuard

class ExampleDelegate: SpeziAppDelegate { override var configuration: Configuration { Configuration { AccessGuardModule { CodeAccessGuard(.exampleAccessGuard, codeOptions: .fourDigitNumeric, timeout: .minutes(15)) } } } }

extension AccessGuardIdentifier { static let exampleAccessGuard = Self("edu.stanford.spezi.exampleAccessGuard") } ```

Biometric with Access Code Fallback

The AccessGuardModule can also be configured with an access guard that uses either Face ID or Touch ID, if the user has one of these enabled on their device (see Face ID or Touch ID for more information). This is shown in the example below. If biometrics are not available or biometric authentication fails, the user will be asked to enter their access code instead.

```swift import Spezi import SpeziAccessGuard

class ExampleDelegate: SpeziAppDelegate { override var configuration: Configuration { Configuration { AccessGuardModule { BiometricsAccessGuard(.exampleAccessGuard, codeOptions: .fourDigitNumeric, timeout: .minutes(15)) } } } } ```

Fixed Code

The AccessGuardModule can also be configured with a fixed code passed as a string. This is shown in the example below.

```swift import Spezi import SpeziAccessGuard

class ExampleDelegate: SpeziAppDelegate { override var configuration: Configuration { Configuration { AccessGuardModule { FixedAccessGuard(.exampleAccessGuard, code: "1234", codeOptions: .fourDigitNumeric, timeout: .minutes(15)) } } } } ```

Multiple Guards

The AccessGuardModule can also be configured with multiple access guards that use different mechanisms, as shown below. In this example, we create both a biometric-based access guard and an access guard with a fixed code that can be used on different views in the application. Each access guard must have a unique identifier.

```swift import Spezi import SpeziAccessGuard

class ExampleDelegate: SpeziAppDelegate { override var configuration: Configuration { Configuration { AccessGuardModule { BiometricsAccessGuard(.accessGuard1) FixedAccessGuard(.accessGuard2, code: "1234") } } } }

extension AccessGuardIdentifier { static let accessGuard1 = Self("edu.stanford.spezi.exampleAccessGuard1") static let accessGuard2 = Self("edu.stanford.spezi.exampleAccessGuard2") } ```

[!NOTE]
You can learn more about a Module in the Spezi documentation.

3. Configure target properties

To ensure that your application has the necessary permissions for biometrics, follow the steps below to configure the target properties within your Xcode project:

  • Open your project settings in Xcode by selecting PROJECTNAME > TARGETNAME > Info tab.
  • Add a key named Privacy - Face ID Usage Description to the Custom iOS Target Properties (the Info.plist file) and provide a string value that describes why your application needs access to Face ID.

This entry is mandatory for apps that utilize biometrics. Failing to provide it will result in your app being unable to access these features.

Examples

Setting an Access Code

Using SetAccessGuard, we can create a view that allows the user to set their access code. This step must be done before access guards can be used to guard a SwiftUI view, with the exception of an access guard that uses a fixed code. (Note that the access guard will be automatically unlocked after the passcode is set until it is locked or times out.)

```swift import SpeziAccessGuard

struct SetAccessCode: View { var body: some View { SetAccessGuard(identifier: .exampleAccessGuard) } } ```

Guarding Access to a SwiftUI View

Now, we can use the AccessGuarded view to guard access to a SwiftUI view with an access code.

```swift import SpeziAccessGuard

struct ProtectedContent: View {
var body: some View { AccessGuarded(.exampleAccessGuard) { Text("Secured content...") } } } ```

Locking an Access Guard

The access guard will lock automatically when it times out. However, we can also lock an access guard directly using the lock(identifier:) method. Here, we add a toolbar item with a button that will lock the access guard.

```swift struct ProtectedContent: View { @Environment(AccessGuard.self) private var accessGuard

var body: some View {
    AccessGuarded(.exampleAccessGuard) {
        Text("Secured content...")
    }
    .toolbar {
        ToolbarItem {
            Button("Lock Access Guard") {
                try? accessGuard.lock(identifier: .exampleAccessGuard)
            }
        }
    }
}

} ```

Resetting an Access Guard

To remove the access code and all information from an access guard, we can use the resetAccessCode(for:) method. Here, we add a toolbar item with a button that will reset the access guard.

```swift struct ProtectedContent: View { @Environment(AccessGuard.self) private var accessGuard

var body: some View {
    AccessGuarded(.exampleAccessGuard) {
        Text("Secured content...")
    }
    .toolbar {
        ToolbarItem {
            Button("Reset Access Guard") {
                try? accessGuard.resetAccessCode(for: .exampleAccessGuard)
            }
        }
    }
}

} ```

For more information, please refer to the API documentation.

Contributing

Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first.

License

This project is licensed under the MIT License. See Licenses for more information.

Spezi Footer Spezi Footer

Owner

  • Name: Stanford Spezi
  • Login: StanfordSpezi
  • Kind: organization

Citation (CITATION.cff)

#
# This source file is part of the Spezi open source project
#
# SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
#
# SPDX-License-Identifier: MIT
# 

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Schmiedmayer"
  given-names: "Paul"
  orcid: "https://orcid.org/0000-0002-8607-9148"
- family-names: "Ravi"
  given-names: "Vishnu"
  orcid: "https://orcid.org/0000-0003-0359-1275"
title: "SpeziAccessGuard"
url: "https://github.com/StanfordSpezi/SpeziAccessGuard"

GitHub Events

Total
  • Create event: 11
  • Release event: 5
  • Issues event: 4
  • Watch event: 1
  • Delete event: 7
  • Issue comment event: 20
  • Push event: 26
  • Pull request review comment event: 49
  • Pull request review event: 51
  • Pull request event: 14
  • Fork event: 2
Last Year
  • Create event: 11
  • Release event: 5
  • Issues event: 4
  • Watch event: 1
  • Delete event: 7
  • Issue comment event: 20
  • Push event: 26
  • Pull request review comment event: 49
  • Pull request review event: 51
  • Pull request event: 14
  • Fork event: 2

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 20
  • Total Committers: 6
  • Avg Commits per committer: 3.333
  • Development Distribution Score (DDS): 0.45
Past Year
  • Commits: 7
  • Committers: 4
  • Avg Commits per committer: 1.75
  • Development Distribution Score (DDS): 0.714
Top Committers
Name Email Commits
Paul Schmiedmayer P****r 11
max-rosenblattl m****l@t****e 2
Vishnu Ravi v****i@g****m 2
Lukas Kollmer h****y@l****e 2
Joan Disho d****n@g****m 2
Leon Nissen 5****n 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 11
  • Total pull requests: 27
  • Average time to close issues: 6 months
  • Average time to close pull requests: 11 days
  • Total issue authors: 2
  • Total pull request authors: 7
  • Average comments per issue: 0.36
  • Average comments per pull request: 1.33
  • Merged pull requests: 24
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 16
  • Average time to close issues: 3 months
  • Average time to close pull requests: 19 days
  • Issue authors: 1
  • Pull request authors: 5
  • Average comments per issue: 1.0
  • Average comments per pull request: 1.69
  • Merged pull requests: 13
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • PSchmiedmayer (8)
  • philippzagar (1)
Pull Request Authors
  • PSchmiedmayer (9)
  • lukaskollmer (4)
  • max-rosenblattl (4)
  • jdisho (4)
  • vishnuravi (3)
  • kneureither (2)
  • LeonNissen (2)
Top Labels
Issue Labels
enhancement (6) good first issue (6) help wanted (3) bug (2) documentation (1)
Pull Request Labels
enhancement (16) bug (4)

Packages

  • Total packages: 1
  • Total downloads: unknown
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 11
swiftpackageindex.com: github.com/StanfordSpezi/SpeziAccessGuard

Spezi Module to Protect Views with an Access Code or Biometrics Authentication

  • Versions: 11
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 14.9%
Dependent repos count: 31.5%
Average: 49.2%
Forks count: 62.7%
Stargazers count: 87.9%
Last synced: 7 months ago

Dependencies

.github/workflows/build-and-test.yml actions
.github/workflows/pull_request.yml actions
Package.swift swiftpm
.github/workflows/monthly-markdown-link-check.yml actions