diff --git a/OktaMobileSDK.xcworkspace/contents.xcworkspacedata b/OktaMobileSDK.xcworkspace/contents.xcworkspacedata index f8090d27e..ae92fcd31 100644 --- a/OktaMobileSDK.xcworkspace/contents.xcworkspacedata +++ b/OktaMobileSDK.xcworkspace/contents.xcworkspacedata @@ -22,6 +22,9 @@ + + diff --git a/OktaMobileSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved b/OktaMobileSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved index 1054ce456..081d230bf 100644 --- a/OktaMobileSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/OktaMobileSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,61 +1,59 @@ { - "object": { - "pins": [ - { - "package": "OktaAuthNative", - "repositoryURL": "https://github.com/okta/okta-auth-swift", - "state": { - "branch": "master", - "revision": "54b40d5c7f7867f6370b0a1311c2e005f57c8bb3", - "version": null - } - }, - { - "package": "OktaOidc", - "repositoryURL": "https://github.com/okta/okta-oidc-ios", - "state": { - "branch": null, - "revision": "91eac722b8e859ba7f15d65a9085a64a296bc065", - "version": "3.11.2" - } - }, - { - "package": "swift-argument-parser", - "repositoryURL": "https://github.com/apple/swift-argument-parser.git", - "state": { - "branch": null, - "revision": "f3c9084a71ef4376f2fabbdf1d3d90a49f1fabdb", - "version": "1.1.2" - } - }, - { - "package": "swift-crypto", - "repositoryURL": "https://github.com/apple/swift-crypto.git", - "state": { - "branch": null, - "revision": "ddb07e896a2a8af79512543b1c7eb9797f8898a5", - "version": "1.1.7" - } - }, - { - "package": "SwiftDocCPlugin", - "repositoryURL": "https://github.com/apple/swift-docc-plugin", - "state": { - "branch": null, - "revision": "3303b164430d9a7055ba484c8ead67a52f7b74f6", - "version": "1.0.0" - } - }, - { - "package": "SwiftOTP", - "repositoryURL": "https://github.com/lachlanbell/SwiftOTP", - "state": { - "branch": null, - "revision": "315acdb759083fd8f3c37b02fc021321c8934f9c", - "version": "3.0.0" - } + "pins" : [ + { + "identity" : "okta-auth-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/okta/okta-auth-swift", + "state" : { + "branch" : "master", + "revision" : "54b40d5c7f7867f6370b0a1311c2e005f57c8bb3" } - ] - }, - "version": 1 + }, + { + "identity" : "okta-oidc-ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/okta/okta-oidc-ios", + "state" : { + "revision" : "91eac722b8e859ba7f15d65a9085a64a296bc065", + "version" : "3.11.2" + } + }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser.git", + "state" : { + "revision" : "41982a3656a71c768319979febd796c6fd111d5c", + "version" : "1.5.0" + } + }, + { + "identity" : "swift-crypto", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-crypto.git", + "state" : { + "revision" : "ddb07e896a2a8af79512543b1c7eb9797f8898a5", + "version" : "1.1.7" + } + }, + { + "identity" : "swift-docc-plugin", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-docc-plugin", + "state" : { + "revision" : "3303b164430d9a7055ba484c8ead67a52f7b74f6", + "version" : "1.0.0" + } + }, + { + "identity" : "swiftotp", + "kind" : "remoteSourceControl", + "location" : "https://github.com/lachlanbell/SwiftOTP", + "state" : { + "revision" : "315acdb759083fd8f3c37b02fc021321c8934f9c", + "version" : "3.0.0" + } + } + ], + "version" : 2 } diff --git a/Samples/JWTSignIn/JWTSignIn.xcodeproj/project.pbxproj b/Samples/JWTSignIn/JWTSignIn.xcodeproj/project.pbxproj new file mode 100644 index 000000000..967533457 --- /dev/null +++ b/Samples/JWTSignIn/JWTSignIn.xcodeproj/project.pbxproj @@ -0,0 +1,351 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + E02042D72C6582DF0088BB34 /* JWTSignin.swift in Sources */ = {isa = PBXBuildFile; fileRef = E02042D62C6582DF0088BB34 /* JWTSignin.swift */; }; + E02042E12C6585090088BB34 /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = E02042E02C6585090088BB34 /* ArgumentParser */; }; + E02042E42C6585200088BB34 /* AuthFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = E02042E32C6585200088BB34 /* AuthFoundation */; }; + E02042E62C6585200088BB34 /* OktaOAuth2 in Frameworks */ = {isa = PBXBuildFile; productRef = E02042E52C6585200088BB34 /* OktaOAuth2 */; }; + E02042E82C658D420088BB34 /* JWTSignin+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E02042E72C658D420088BB34 /* JWTSignin+Extensions.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + E02042D12C6582DF0088BB34 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + E02042D32C6582DF0088BB34 /* JWTSignIn */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = JWTSignIn; sourceTree = BUILT_PRODUCTS_DIR; }; + E02042D62C6582DF0088BB34 /* JWTSignin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JWTSignin.swift; sourceTree = ""; }; + E02042DD2C65831B0088BB34 /* TestConfiguration.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = TestConfiguration.xcconfig; path = ../Shared/TestConfiguration.xcconfig; sourceTree = ""; }; + E02042DE2C65831B0088BB34 /* SampleCode.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = SampleCode.xcconfig; path = ../Shared/SampleCode.xcconfig; sourceTree = ""; }; + E02042E72C658D420088BB34 /* JWTSignin+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JWTSignin+Extensions.swift"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + E02042D02C6582DF0088BB34 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + E02042E12C6585090088BB34 /* ArgumentParser in Frameworks */, + E02042E42C6585200088BB34 /* AuthFoundation in Frameworks */, + E02042E62C6585200088BB34 /* OktaOAuth2 in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + E02042CA2C6582DF0088BB34 = { + isa = PBXGroup; + children = ( + E02042D52C6582DF0088BB34 /* JWTSignIn */, + E02042DE2C65831B0088BB34 /* SampleCode.xcconfig */, + E02042DD2C65831B0088BB34 /* TestConfiguration.xcconfig */, + E02042D42C6582DF0088BB34 /* Products */, + E02042E22C6585200088BB34 /* Frameworks */, + ); + sourceTree = ""; + }; + E02042D42C6582DF0088BB34 /* Products */ = { + isa = PBXGroup; + children = ( + E02042D32C6582DF0088BB34 /* JWTSignIn */, + ); + name = Products; + sourceTree = ""; + }; + E02042D52C6582DF0088BB34 /* JWTSignIn */ = { + isa = PBXGroup; + children = ( + E02042D62C6582DF0088BB34 /* JWTSignin.swift */, + E02042E72C658D420088BB34 /* JWTSignin+Extensions.swift */, + ); + path = JWTSignIn; + sourceTree = ""; + }; + E02042E22C6585200088BB34 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + E02042D22C6582DF0088BB34 /* JWTSignIn */ = { + isa = PBXNativeTarget; + buildConfigurationList = E02042DA2C6582DF0088BB34 /* Build configuration list for PBXNativeTarget "JWTSignIn" */; + buildPhases = ( + E02042CF2C6582DF0088BB34 /* Sources */, + E02042D02C6582DF0088BB34 /* Frameworks */, + E02042D12C6582DF0088BB34 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = JWTSignIn; + packageProductDependencies = ( + E02042E02C6585090088BB34 /* ArgumentParser */, + E02042E32C6585200088BB34 /* AuthFoundation */, + E02042E52C6585200088BB34 /* OktaOAuth2 */, + ); + productName = JWTSignIn; + productReference = E02042D32C6582DF0088BB34 /* JWTSignIn */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + E02042CB2C6582DF0088BB34 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1540; + LastUpgradeCheck = 1540; + TargetAttributes = { + E02042D22C6582DF0088BB34 = { + CreatedOnToolsVersion = 15.4; + }; + }; + }; + buildConfigurationList = E02042CE2C6582DF0088BB34 /* Build configuration list for PBXProject "JWTSignIn" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = E02042CA2C6582DF0088BB34; + packageReferences = ( + E02042DF2C6585090088BB34 /* XCRemoteSwiftPackageReference "swift-argument-parser" */, + ); + productRefGroup = E02042D42C6582DF0088BB34 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + E02042D22C6582DF0088BB34 /* JWTSignIn */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + E02042CF2C6582DF0088BB34 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E02042D72C6582DF0088BB34 /* JWTSignin.swift in Sources */, + E02042E82C658D420088BB34 /* JWTSignin+Extensions.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + E02042D82C6582DF0088BB34 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = E02042DE2C65831B0088BB34 /* SampleCode.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + E02042D92C6582DF0088BB34 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = E02042DE2C65831B0088BB34 /* SampleCode.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + }; + name = Release; + }; + E02042DB2C6582DF0088BB34 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = E02042DE2C65831B0088BB34 /* SampleCode.xcconfig */; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_BUNDLE_IDENTIFIER = "com.example.okta-sample.DeviceAuthSignIn${SAMPLE_CODE_DISAMBIGUATOR}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + E02042DC2C6582DF0088BB34 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = E02042DE2C65831B0088BB34 /* SampleCode.xcconfig */; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_BUNDLE_IDENTIFIER = "com.example.okta-sample.DeviceAuthSignIn${SAMPLE_CODE_DISAMBIGUATOR}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + E02042CE2C6582DF0088BB34 /* Build configuration list for PBXProject "JWTSignIn" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E02042D82C6582DF0088BB34 /* Debug */, + E02042D92C6582DF0088BB34 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + E02042DA2C6582DF0088BB34 /* Build configuration list for PBXNativeTarget "JWTSignIn" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E02042DB2C6582DF0088BB34 /* Debug */, + E02042DC2C6582DF0088BB34 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + E02042DF2C6585090088BB34 /* XCRemoteSwiftPackageReference "swift-argument-parser" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/apple/swift-argument-parser.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 1.5.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + E02042E02C6585090088BB34 /* ArgumentParser */ = { + isa = XCSwiftPackageProductDependency; + package = E02042DF2C6585090088BB34 /* XCRemoteSwiftPackageReference "swift-argument-parser" */; + productName = ArgumentParser; + }; + E02042E32C6585200088BB34 /* AuthFoundation */ = { + isa = XCSwiftPackageProductDependency; + productName = AuthFoundation; + }; + E02042E52C6585200088BB34 /* OktaOAuth2 */ = { + isa = XCSwiftPackageProductDependency; + productName = OktaOAuth2; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = E02042CB2C6582DF0088BB34 /* Project object */; +} diff --git a/Samples/JWTSignIn/JWTSignIn.xcodeproj/xcshareddata/xcschemes/JWTSignIn.xcscheme b/Samples/JWTSignIn/JWTSignIn.xcodeproj/xcshareddata/xcschemes/JWTSignIn.xcscheme new file mode 100644 index 000000000..f5a0c1bd5 --- /dev/null +++ b/Samples/JWTSignIn/JWTSignIn.xcodeproj/xcshareddata/xcschemes/JWTSignIn.xcscheme @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Samples/JWTSignIn/JWTSignIn/JWTSignin+Extensions.swift b/Samples/JWTSignIn/JWTSignIn/JWTSignin+Extensions.swift new file mode 100644 index 000000000..b8cbaeac1 --- /dev/null +++ b/Samples/JWTSignIn/JWTSignIn/JWTSignin+Extensions.swift @@ -0,0 +1,46 @@ +// +// Copyright (c) 2024-Present, Okta, Inc. and/or its affiliates. All rights reserved. +// The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") +// +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and limitations under the License. +// + +import Foundation +import AuthFoundation +import ArgumentParser + +extension URL: ExpressibleByArgument { + public init?(argument: String) { + self.init(string: argument) + } +} + +extension JWTSignin { + var fileHandle: FileHandle? { + get throws { + guard let file else { return nil } + if file.path() == "-" { + return .standardInput + } + + return try FileHandle(forReadingFrom: file) + } + } + + func assertionString() throws -> String { + if let file = try fileHandle, + let data = try file.readToEnd(), + let string = String(data: data, encoding: .utf8) + { + return string + } + + throw ValidationError("Assertion input file is empty.") + } +} + diff --git a/Samples/JWTSignIn/JWTSignIn/JWTSignin.swift b/Samples/JWTSignIn/JWTSignIn/JWTSignin.swift new file mode 100644 index 000000000..aa0906014 --- /dev/null +++ b/Samples/JWTSignIn/JWTSignIn/JWTSignin.swift @@ -0,0 +1,83 @@ +// +// Copyright (c) 2024-Present, Okta, Inc. and/or its affiliates. All rights reserved. +// The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") +// +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and limitations under the License. +// + +import Foundation +import ArgumentParser +import OktaOAuth2 + +@main +struct JWTSignin: AsyncParsableCommand { + @Option( + name: [.long, .short], + help: "The application's issuer URL.") + var issuer: URL + + @Option(name: [.long, .short], help: "The application's client ID.") + var clientId: String + + @Option(name: [.long, .short], help: "The scopes to use.") + var scopes: String = "openid profile" + + @Option( + name: [.long, .short], + help: "JWT assertion string to use", + transform: JWT.init(_:)) + var assertion: JWT? + + @Argument( + help: "A file containing the JWT assertion. If `-` it reads from stdin.", + completion: .file(), + transform: URL.init(fileURLWithPath:)) + var file: URL? = nil + + mutating func validate() throws { + if assertion == nil, file == nil { + throw ValidationError("You must supply one of --inputFile or --assertion.") + } + + guard assertion != nil || file != nil + else { + throw ValidationError("You can not use both --inputFile and --assertion.") + } + + if assertion == nil { + assertion = try JWT(try assertionString()) + } + } + + mutating func run() async throws { + guard let assertion = assertion else { + throw ValidationError("Invalid assertion supplied") + } + + let flow = JWTAuthorizationFlow(issuer: issuer, + clientId: clientId, + scopes: scopes) + let token = try await flow.start(with: assertion) + printUserInfo(using: token) + } + + func printUserInfo(using token: Token) { + if let idToken = token.idToken { + print(""" + Name: \(idToken.name ?? "N/A") + Locale: \(idToken.userLocale?.identifier ?? "N/A") + Timezone: \(idToken.timeZone?.identifier ?? "N/A") + + Username: \(idToken.preferredUsername ?? "N/A") + User ID: \(idToken.subject ?? "N/A") + """) + } else { + print("No ID token returned.") + } + } +} diff --git a/Samples/JWTSignIn/README.md b/Samples/JWTSignIn/README.md new file mode 100644 index 000000000..b8e5daf47 --- /dev/null +++ b/Samples/JWTSignIn/README.md @@ -0,0 +1,42 @@ +# JWTSignIn + +## Abstract + +Sign in with a signed JWT through the JWT Bearer Authorization flow. + +## Overview + +The command-line interface (CLI) app in the sample requires four pieces of information: + +- The issuer URL for your Okta org authorization server. This is usually the domain of your registered Okta org followed by `/oauth2/default`, such as `https://example.okta.com/oauth2/default`. +- The client ID from the Okta Org Application Integration from the Okta Admin console, such as `0uxa9VpZDRCeFh3Nkk2V`. +- The permissions, or OAuth scopes that are requested by the application, such as `openid` or `profile`. +- The JWT assertion, either supplied as a command-line argument, or loaded from a file. + +The JWT assertion can be supplied through a command-line argument: + +```zsh +$ JWTSignIn --client-id 0uxa9VpZDRCeFh3Nkk2V \ + --issuer https://example.okta.com/oauth2/default \ + --scopes "openid profile" \ + --assertion +``` + +Alternatively a file can be specified in a file (use a filename of `-` to read the JWT assertion from STDIN). + +```zsh +$ JWTSignIn --client-id 0uxa9VpZDRCeFh3Nkk2V \ + --issuer https://example.okta.com/oauth2/default \ + --scopes "openid profile" \ + --file ./assertion.json +``` + +## Running the App + +You can run the app from the command line, or by using the Build and Run command in Xcode and providing the command line argument values in your scheme. + +To find the full path for the executable of the app: + +1. Build the app in Xcode. +2. In the Project Navigator window, select `JWTSignIn` in the Products folder. +3. The full path is shown in the File Inspector. diff --git a/Samples/UserPasswordSignIn/README.md b/Samples/UserPasswordSignIn/README.md index 43eb81ee4..b87f9ab52 100644 --- a/Samples/UserPasswordSignIn/README.md +++ b/Samples/UserPasswordSignIn/README.md @@ -8,8 +8,8 @@ Add sign-in with a username and password to a macOS app. The command-line interface (CLI) app in the sample requires five pieces of information: -- The issuer URL for your Okta org authorization server. This is usually the domain of your registered Okta org followed by `/oauth2/default`, such as `https://dev-1234567.okta.com/oauth2/default`. -- The client ID from the Okta Org Application Integration from the Okta Admin console, such as `0ux3rutxocxFX9xyz3t9`. +- The issuer URL for your Okta org authorization server. This is usually the domain of your registered Okta org followed by `/oauth2/default`, such as `https://example.okta.com/oauth2/default`. +- The client ID from the Okta Org Application Integration from the Okta Admin console, such as `0uxa9VpZDRCeFh3Nkk2V`. - The permissions, or OAuth scopes that are requested by the application, such as `openid` or `profile`. - The username. - The password. @@ -17,7 +17,9 @@ The command-line interface (CLI) app in the sample requires five pieces of infor You provide the first three items as command-line arguments. For example: ```zsh -$ UserPasswordSignIn --client-id 0ux3rutxocxFX9xyz3t9 --issuer https://dev-1234567.okta.com/oauth2/default --scopes "openid profile" +$ UserPasswordSignIn --client-id 0uxa9VpZDRCeFh3Nkk2V \ + --issuer https://example.okta.com/oauth2/default \ + --scopes "openid profile" ``` The app prompts for the username and then the password. diff --git a/Samples/UserPasswordSignIn/UserPasswordSignIn.xcodeproj/project.pbxproj b/Samples/UserPasswordSignIn/UserPasswordSignIn.xcodeproj/project.pbxproj index bff060d65..b9cb38fc9 100644 --- a/Samples/UserPasswordSignIn/UserPasswordSignIn.xcodeproj/project.pbxproj +++ b/Samples/UserPasswordSignIn/UserPasswordSignIn.xcodeproj/project.pbxproj @@ -299,7 +299,6 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 12.1; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -355,7 +354,6 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 12.1; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = macosx;