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

Allow device identifier to be passed as a parameter #149

Merged
merged 5 commits into from
Feb 29, 2024
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
4 changes: 3 additions & 1 deletion .github/workflows/documentation-ghpages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ on:
- '*'

env:
DEVELOPER_DIR: /Applications/Xcode_13.3.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
NSUnbufferedIO: YES


# NOTE: The DocC `generate-documentation` plugin does not handle the
# hostingBasePath well. In particular, it doesn't properly handle
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ on:
- 'Sources/**/*.md'

env:
DEVELOPER_DIR: /Applications/Xcode_13.3.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
NSUnbufferedIO: YES

jobs:
BuildDocumentation:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/uitests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
- completed

env:
DEVELOPER_DIR: /Applications/Xcode_13.3.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
NSUnbufferedIO: YES

jobs:
UITest-EmbeddedAuth:
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/unittests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ on:
- 'Samples/**/*.swift'
- 'Tests/**/*.swift'

env:
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
NSUnbufferedIO: YES

jobs:
SwiftBuild:
name: Swift Unit Tests
runs-on: macos-12
timeout-minutes: 10
env:
DEVELOPER_DIR: /Applications/Xcode_13.3.app/Contents/Developer
steps:
- uses: actions/checkout@master
- name: Build
Expand All @@ -44,8 +46,6 @@ jobs:
timeout-minutes: 10
needs:
- SwiftBuild
env:
DEVELOPER_DIR: /Applications/Xcode_13.3.app/Contents/Developer
steps:
- uses: actions/checkout@master
- name: Lint CocoaPods
Expand All @@ -55,8 +55,6 @@ jobs:
name: Xcode Unit Tests
runs-on: macos-12
timeout-minutes: 10
env:
DEVELOPER_DIR: /Applications/Xcode_13.3.app/Contents/Developer
steps:
- uses: actions/checkout@master
- name: Test OktaIdx
Expand Down
10 changes: 5 additions & 5 deletions OktaIdx.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'OktaIdx'
spec.version = '3.1.1'
spec.version = '3.2.0'
spec.summary = 'SDK to easily integrate the Okta Identity Engine'
spec.description = <<-DESC
Integrate your native app with Okta using the Okta Identity Engine library.
Expand All @@ -9,20 +9,20 @@ Integrate your native app with Okta using the Okta Identity Engine library.
:ios => "10.0",
:tvos => "10.0",
:watchos => "7.0",
:osx => "10.11"
:osx => "10.12"
}
spec.ios.deployment_target = "10.0"
spec.tvos.deployment_target = "10.0"
spec.watchos.deployment_target = "7.0"
spec.osx.deployment_target = "10.11"
spec.osx.deployment_target = "10.12"

spec.homepage = 'https://github.com/okta/okta-idx-swift'
spec.license = { :type => 'APACHE2', :file => 'LICENSE' }
spec.authors = { "Okta Developers" => "[email protected]"}
spec.source = { :git => 'https://github.com/okta/okta-idx-swift.git', :tag => spec.version.to_s }

spec.source_files = 'Sources/OktaIdx/**/*.swift'
spec.swift_version = "5.5"
spec.swift_version = "5.6"

spec.dependency "OktaAuthFoundation", "~> 1.5.0"
spec.dependency "OktaAuthFoundation", "~> 1.6.1"
end
25 changes: 12 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -7,22 +7,26 @@ var package = Package(
name: "OktaIdx",
defaultLocalization: "en",
platforms: [
.iOS(.v9),
.tvOS(.v9),
.iOS(.v10),
.tvOS(.v10),
.watchOS(.v7),
.macOS(.v10_11)
.macOS(.v10_12),
.macCatalyst(.v13)
],
products: [
.library(name: "OktaIdx", targets: ["OktaIdx"])
],
dependencies: [
.package(name: "AuthFoundation",
url: "https://github.com/okta/okta-mobile-swift",
from: "1.5.0")
.package(url: "https://github.com/okta/okta-mobile-swift",
from: "1.6.1"),
.package(url: "https://github.com/apple/swift-docc-plugin",
from: "1.0.0")
],
targets: [
.target(name: "OktaIdx",
dependencies: ["AuthFoundation"]),
dependencies: [
.product(name: "AuthFoundation", package: "okta-mobile-swift")
]),
.target(name: "TestCommon",
dependencies: ["OktaIdx"],
path: "Tests/TestCommon"),
Expand All @@ -32,8 +36,3 @@ var package = Package(
],
swiftLanguageVersions: [.v5]
)

#if swift(>=5.6)
package.dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"))
#endif

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This library uses semantic versioning and follows Okta's [Library Version Policy
| ------- | ---------------------------------- |
| 1.0.0 | |
| 2.0.1 | |
| 3.1.1 | ✔️ Stable |
| 3.2.0 | ✔️ Stable |

The latest release can always be found on the [releases page][github-releases].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ extension InteractionCodeFlow {

/// Unique identifier for this device, encoded to limit the character count. This is used within
/// an outgoing Cookie named `dt` to enable "Remember this device" trust options within OIE.
static var deviceIdentifier: String? {
guard var identifier = systemDeviceIdentifier ?? keychainDeviceIdentifier
var deviceIdentifierString: String? {
guard let identifier = deviceIdentifier ?? Self.systemDeviceIdentifier ?? Self.keychainDeviceIdentifier
else {
return nil
}

let data = Data(bytes: &identifier, count: 16)
var bytes = identifier.uuid
let data = Data(bytes: &bytes, count: 16)
let deviceToken = data.base64EncodedString()

return deviceToken
}
}
Expand Down
18 changes: 15 additions & 3 deletions Sources/OktaIdx/InteractionCodeFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public final class InteractionCodeFlow: AuthenticationFlow {
/// The application's redirect URI.
public let redirectUri: URL

/// The UUID to use to identify this device when using "Remeber This Device".
///
/// If this value is not supplied to the initializer, a default may be automatically generated at runtime.
public let deviceIdentifier: UUID?

/// Any additional query string parameters you would like to supply to the authorization server.
public let additionalParameters: [String: String]?

Expand Down Expand Up @@ -87,14 +92,18 @@ public final class InteractionCodeFlow: AuthenticationFlow {
/// - clientId: The client ID
/// - scopes: The scopes to request
/// - redirectUri: The redirect URI for the client.
/// - additionalParameters: Optional parameters to include on the authorize URI.
/// - deviceIdentifier: Optional UUID to use to identify this device when using "Remeber This Device".
public convenience init(issuer: URL,
clientId: String,
scopes: String,
redirectUri: URL,
additionalParameters: [String: String]? = nil)
additionalParameters: [String: String]? = nil,
deviceIdentifier: UUID? = nil)
{
self.init(redirectUri: redirectUri,
additionalParameters: additionalParameters,
deviceIdentifier: deviceIdentifier,
client: OAuth2Client(baseURL: issuer,
clientId: clientId,
scopes: scopes))
Expand All @@ -103,9 +112,12 @@ public final class InteractionCodeFlow: AuthenticationFlow {
/// Initializer to construct an authentication flow from a pre-defined configuration and client.
/// - Parameters:
/// - configuration: The configuration to use for this authentication flow.
/// - additionalParameters: Optional parameters to include on the authorize URI.
/// - deviceIdentifier: Optional UUID to use to identify this device when using "Remeber This Device".
/// - client: The `OAuth2Client` to use with this flow.
public init(redirectUri: URL,
additionalParameters: [String: String]? = nil,
deviceIdentifier: UUID? = nil,
client: OAuth2Client)
{
// Ensure this SDK's static version is included in the user agent.
Expand All @@ -114,7 +126,7 @@ public final class InteractionCodeFlow: AuthenticationFlow {
self.client = client
self.redirectUri = redirectUri
self.additionalParameters = additionalParameters

self.deviceIdentifier = deviceIdentifier
client.add(delegate: self)
}

Expand Down Expand Up @@ -334,7 +346,7 @@ public final class InteractionCodeFlow: AuthenticationFlow {

// MARK: Private properties / methods
private(set) lazy var deviceTokenCookie: HTTPCookie? = {
guard let deviceToken = InteractionCodeFlow.deviceIdentifier,
guard let deviceToken = deviceIdentifierString,
let host = client.baseURL.host
else {
return nil
Expand Down
2 changes: 1 addition & 1 deletion Sources/OktaIdx/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

import Foundation

public let Version = SDKVersion(sdk: "okta-idx-swift", version: "3.1.1")
public let Version = SDKVersion(sdk: "okta-idx-swift", version: "3.2.0")
14 changes: 13 additions & 1 deletion Tests/OktaIdxTests/DeviceIdentifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import XCTest
@testable import OktaIdx

#if SWIFT_PACKAGE
@testable import TestCommon
#endif

#if canImport(UIKit)
import UIKit
#endif
Expand All @@ -34,7 +38,15 @@ final class DeviceIdentifierTests: XCTestCase {

#if canImport(UIKit) && (os(iOS) || os(macOS) || os(tvOS) || canImport(WatchKit))
func testDeviceIdentifier() throws {
let identifier = try XCTUnwrap(InteractionCodeFlow.deviceIdentifier)
let urlSession = URLSessionMock()
let issuer = try XCTUnwrap(URL(string: "https://example.com/oauth2/default"))
let redirectUri = try XCTUnwrap(URL(string: "redirect:/uri"))
let client = OAuth2Client(baseURL: issuer,
clientId: "clientId",
scopes: "openid profile",
session: urlSession)
let flow = InteractionCodeFlow(redirectUri: redirectUri, client: client)
let identifier = try XCTUnwrap(flow.deviceIdentifierString)

// Device Token string _must_ be 32 characters or less.
XCTAssertLessThanOrEqual(identifier.count, 32)
Expand Down
2 changes: 1 addition & 1 deletion Tests/OktaIdxTests/InteractionCodeFlowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class InteractionCodeFlowTests: XCTestCase {
XCTAssertEqual(delegate.calls.count, 1)
XCTAssertEqual(delegate.calls.first?.type, .response)

if InteractionCodeFlow.deviceIdentifier != nil {
if flow.deviceIdentifierString != nil {
let deviceToken = try XCTUnwrap(flow.deviceTokenCookie?.value)
XCTAssertEqual(urlSession.requests.first?.allHTTPHeaderFields?["Cookie"],
"DT=\(deviceToken)")
Expand Down
Loading