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

📖 Docs: Auth DocC documentation #11

Merged
merged 1 commit into from
Nov 5, 2023
Merged
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
114 changes: 114 additions & 0 deletions Documentation.docc/Auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Auth

Scribble Lab's Auth Services

## Overview

The ScribbleLab Auth Service is a secure, reliable and easy-to-use authentication service that allows users to gain access to the application's resources through a simple and straightforward process. The ScribbleLab Auth Service is built on top of Firebase, a powerful and scalable database service, ensuring that user authentication is done in a secure and robust manner.

We offer our users three ways to authenticate:
- Google Sign In **``(GID)``**
- SignInWithApple **``(SIWA)``**
- ScribbleLabApp Account **``(SLA)`**

All three ways are secure due to our secured database.

### How is Firebase connected to our App?
- In order to use Firebase you need to import Firebase via SPM and import it in your AppFile as following:
```swift
import SwiftUI
import FirebaseCore
```

- Then you need to add Firebase to your AppDelegate:
```swift
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()

return true
}
}
```

> For the use for GID:
> In order to use GID (= GoogleSignIn) you need to add GoogleSignIn to your Project via SPM. Then import it in your AppFile.
>```swift
> import SwiftUI
> import FirebaseCore
> import GoogleSignIn
> ```
>
> Then add the following code to your AppDelegate in order to let GID run properly:
> ```swift
> // The method should call the handleURL method of GIDSignIn instance, which will properly handle the URL that SL recieves at the end of the auth process.
>@available(iOS 9.0, *)
>func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
> return GIDSignIn.sharedInstance.handle(url)
>}
> ```

- Firebase is now succesfully conected from your App site 🎉

### How does our Authentication work?
While the App is launching it checks wether you have a valide UserSession (email, password, uuid). In order to do that we call our ``ContentViewModel`` that asks FirebaseAuth after a valide user session:

```swift
private let service = SLAuthService.shared
private var canellables = Set<AnyCancellable>()

@Published var userSession: FirebaseAuth.User?
@Published var currentUser: User?

init() {
setupSubscribers()
}

func setupSubscribers() {
service.$userSession.sink { [weak self] userSession in
self?.userSession = userSession
}
.store(in: &canellables)

service.$currentUser.sink { [weak self] currentUser in
self?.currentUser = currentUser
}
.store(in: &canellables)
}
```



> ContentView.swift:
> ```swift
> import SwiftUI
>
> struct ContentView: View {
> @StateObject var viewModel = ContentViewModel()
>
> var body: some View {
> Group {
> if $viewModel.userSession == nil {
> SignUpView()
> } else if let currentUser = viewModel.currentUser {
> SLSideBarView()
> }
> }
> }
>}
> ```

While this is all happening our ``ContentViewModel`` also calls the ``SLAuthService`` that tries to fetch the user:
```swift
@MainActor
func loadUserData() async throws {
self.userSession = Auth.auth().currentUser
guard let currentUid = userSession?.uid else { return }
self.currentUser = try await UserService.fetchUser(withUid: currentUid)
}
```

### Section header

<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->
25 changes: 25 additions & 0 deletions Documentation.docc/AuthFlow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# AuthFlow

ScribbleLab's Auth flow

## Overview

The Auth Flow is a process that allows users to securely access an application or service by verifying their identity. This process typically involves the use of a username and password, but may also incorporate other forms of authentication such as biometric identification or two-factor authentication.

Here is a breakdown of the steps involved in the Auth Flow:

1. User initiates the Auth Flow: At the first launch the user will be navigated to our ``SignUpView``. If the user already has an account they'll be navigated to the ``LogInView``.

2. User enters their login credentials: The user provides their username/email and password, or other forms of authentication such as biometric identification or two-factor authentication.

3. Application verifies credentials: The application verifies the user's credentials against our Firestore Database. If the credentials are valid, the application grants the user access to the service.

4. Session creation: Once the user has been authenticated, the application creates a session for the user. This session is a unique identifier that allows the application to recognize the user and their access rights for the duration of their visit to the application or service.

5. User performs actions within the application: The user is now able to perform actions within the application or service according to their access rights.

6. Session expiration: Once the user has finished using the application or service, the session is terminated. This is done to ensure the security of the user's data and prevent unauthorized access.

### Section header

<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->
21 changes: 17 additions & 4 deletions Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where personal information can fall into the wrong hands. But with ScribbleLab i
When you create a ScribbleLab account, you are agreeing to our [License Agreement](LICENSE_AGREEMENT.md) as well as the licenses of our third-party packages. You might be wondering if it's safe to create an account with ScribbleLab. The answer is yes! We use [Google Firebase](https://firebase.google.com/), which includes [FirebaseAuth](https://firebase.google.com/docs/auth?hl=en), [FirebaseStorage](https://firebase.google.com/docs/storage?hl=en), and [Cloud Firestore](https://firebase.google.com/docs/firestore?hl=en), to securely store your data. This means that no one can access your data, not even us. We cannot see any of your personal data, such as created documents or cloud services. The only thing we can see is how many people have a ScribbleLab account. Furthermore we use Additionally, we use [Google Analytics](https://developers.google.com/analytics?hl=en) and [Google Crashlytics](https://firebase.google.com/docs/crashlytics?hl=en) to track crashes and other unusual events or bugs.

> Developer note:
>
> It is not permissible for you to alter any authentication code unless you have been explicitly authorized to do so. If you do so we'll close your PR accordingly ⛔️.

Ensuring the security of our software is a top priority for us, we regularly release software updates that include bug fixes and security
patches to keep your data and system secure. It is important to install these updates as soon as they become available to ensure that
Expand All @@ -80,10 +80,23 @@ instructions carefully to ensure a smooth update process.
Remember, staying up to date with software updates is an essential part of maintaining the security and integrity of your system.

> Note:
> No warranty is provided for testing Alpha, Beta, nightly, or RC builds. Use at your own risk.
> No warranty is provided for testing Alpha, Beta, nightly, or RC builds. Use at your own risk. You also need Xcode 15 installed and the iPadOS 17 Simualtor.
> ### Device Reccomendation
> We reccomend testing our App on those devices:
> | iPadOS | iOS | macOS| visionOS |
> | :----: | :--: | :--: | :----: |
> | iPad Pro 11 | iPhone 15 Pro | n/a | Apple Vision Pro |

## Topics
- <doc:Auth>
- <doc:AuthFlow>

### Application
- ``ScribbleLabApp``
- ``ContentView``
- ``SLAuthService``
- ``LogInView``
- ``SignUpView``
- ``SLSideBarView``

### <!--@START_MENU_TOKEN@-->Group<!--@END_MENU_TOKEN@-->

- <!--@START_MENU_TOKEN@-->``Symbol``<!--@END_MENU_TOKEN@-->
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
<key>text-context</key>
<dict>
<key>focused</key>
<string>// .environmentObject(RegistrationViewModel())
<string> /// then call the declared isDarkMode argument.
</string>
<key>leading</key>
<string> .environmentObject(ContentViewModel())
// SignUpView()
<string> ///
/// To call the darkmode state add the @AppStorage property at the top in your Struct
</string>
<key>trailing</key>
<string>// .environmentObject(SignInWithGoogleModel())
.preferredColorScheme(isDarkMode ? .dark : .light)
}
<string> @AppStorage("isDarkMode") private var isDarkMode = false

var body: some Scene {
</string>
</dict>
<key>type</key>
Expand Down Expand Up @@ -98,16 +98,16 @@
<key>text-context</key>
<dict>
<key>focused</key>
<string> ContentView()
<string> /// - true: Dark mode is enabled
</string>
<key>leading</key>
<string> var body: some Scene {
WindowGroup {
<string> /// Possible values:
/// - false: Dark mode isn't enabled
</string>
<key>trailing</key>
<string> .environmentObject(ContentViewModel())
// SignUpView()
// .environmentObject(RegistrationViewModel())
<string> ///
/// To call the darkmode state add the @AppStorage property at the top in your Struct
/// then call the declared isDarkMode argument.
</string>
</dict>
<key>title</key>
Expand Down
Loading