Skip to content

Commit

Permalink
SDK and Example Project (#3)
Browse files Browse the repository at this point in the history
* Adding sdk and example project

* Logged in page is now user credential list

* Unit tests + DocC

* UI Tweaks and README

* Point project to BW account

* Add testing workflow

* Added requirements section in README
  • Loading branch information
victor-livefront authored Jul 10, 2024
1 parent 8004075 commit 94eb8c5
Show file tree
Hide file tree
Showing 75 changed files with 3,983 additions and 2 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test

on:
pull_request:
branches:
- main

env:
DEVELOPER_DIR: /Applications/Xcode_15.2.app/Contents/Developer
SIMULATOR_DESTINATION: platform=iOS Simulator,name=iPhone 15 Pro,OS=17.2

jobs:
check-run:
name: Check PR run
uses: bitwarden/gh-actions/.github/workflows/check-run.yml@main

test:
name: Test
runs-on: macos-14

steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Test
run: |
set -o pipefail && \
xcodebuild test \
-scheme Passwordless \
-destination "${{ env.SIMULATOR_DESTINATION }}" \
-derivedDataPath build/DerivedData \
| xcbeautify --renderer github-actions
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# macOS
.DS_Store

## User settings
xcuserdata/

.swiftpm
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# How to Contribute

Our [Contributing Guidelines](https://contributing.bitwarden.com/contributing/) are located in our [Contributing Documentation](https://contributing.bitwarden.com/). The documentation also includes recommended tooling, code style tips, and lots of other great information to get you started.
496 changes: 496 additions & 0 deletions Example/DemoPasswordless.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "578159A82C29EF41006F3C20"
BuildableName = "DemoPasswordless.app"
BlueprintName = "DemoPasswordless"
ReferencedContainer = "container:DemoPasswordless.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "578159A82C29EF41006F3C20"
BuildableName = "DemoPasswordless.app"
BlueprintName = "DemoPasswordless"
ReferencedContainer = "container:DemoPasswordless.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "578159A82C29EF41006F3C20"
BuildableName = "DemoPasswordless.app"
BlueprintName = "DemoPasswordless"
ReferencedContainer = "container:DemoPasswordless.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "1024.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Example/DemoPasswordless/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "logo.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xDC",
"green" : "0x5D",
"red" : "0x17"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xFF",
"green" : "0xC5",
"red" : "0xB2"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xFF",
"green" : "0xFF",
"red" : "0xFF"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x00",
"green" : "0x00",
"red" : "0x00"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
10 changes: 10 additions & 0 deletions Example/DemoPasswordless/DemoApp.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?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>com.apple.developer.associated-domains</key>
<array>
<string>webcredentials:demo.passwordless.dev</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Foundation

class DemoAppAPIService {
let demoApiUrl: String

init(demoApiUrl: String) {
self.demoApiUrl = demoApiUrl
}

private func make<T: Decodable>(request: URLRequest, authToken: String? = nil) async -> T {
var updatedRequest = request
updatedRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
if let authToken {
updatedRequest.setValue("Bearer \(authToken)", forHTTPHeaderField: "Authorization")
}

let response = try! await URLSession.shared.data(for: updatedRequest)
let data = response.0
let dataString = String(data: data, encoding: .utf8) ?? "Empty response"
let httpResponse = response.1 as! HTTPURLResponse

print("Status Code: \(httpResponse.statusCode), Body: \(dataString)")
return try! JSONDecoder().decode(T.self, from: data)
}

func register(username: String, firstName: String, lastName: String) async -> DemoRegisterResponse {
let url = URL(string: "\(demoApiUrl)/auth/register")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = try? JSONEncoder().encode(
DemoRegisterRequest(
username: username,
firstName: firstName,
lastName: lastName
)
)
return await make(request: request)
}

func login(verifyToken: String) async -> DemoLoginResponse {
let url = URL(string: "\(demoApiUrl)/auth/login")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = try? JSONEncoder().encode(DemoLoginRequest(token: verifyToken))
return await make(request: request)
}

func fetchCredentials(userId: String, authToken: String) async -> [DemoCredentialsResponse] {
let url = URL(string: "\(demoApiUrl)/users/\(userId)/credentials")!
return await make(request: URLRequest(url: url), authToken: authToken)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Foundation

struct DemoCredentialsResponse: Decodable, Identifiable {
var id: String { publicKey }

let publicKey: String
let userHandle: String
let signatureCounter: Int
let attestationFmt: String
let createdAt: String
let aaGuid: String
let lastUsedAt: String
let rpId: String?
let origin: String
let country: String
let device: String
let nickname: String?
let userId: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

struct DemoLoginRequest: Encodable {
let token: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

struct DemoLoginResponse: Decodable {
let jwtToken: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Foundation

struct DemoRegisterRequest: Encodable {
let username: String
let firstName: String
let lastName: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

struct DemoRegisterResponse: Decodable {
let token: String
}
Loading

0 comments on commit 94eb8c5

Please sign in to comment.