Skip to content

Commit

Permalink
Introduce a convenience property list initializer, to align with Okta…
Browse files Browse the repository at this point in the history
…OAuth2 flows (#110)
  • Loading branch information
mikenachbaur-okta authored Aug 5, 2022
1 parent 04c651c commit 4cfa3c2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Documentation/OIE Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ For specific suggestions on how to implement the various capabilities that `okta
### Configuring and initializing your client

```swift
let config = IDXClient.Configuration(
let flow = InteractionCodeFlow(
issuer: "https://{yourOktaDomain}/oauth2/default",
clientId: "clientId",
clientSecret: nil,
scopes: ["openid", "email", "offline_access"],
redirectUri: "com.myapp:/redirect/uri")

IDXClient.start(configuration: config) { result in
flow.start() { result in
switch result {
case .failure(let error):
// Handle the error
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ When a remediation is selected and its inputs have been supplied by the user, th

The below code snippets will help you understand how to use this library.

Once you initialize an `IDXClient`, you can call methods to make requests to the Okta IDX API. Please see the [configuration reference](#configuration-reference) section for more details.
Once you initialize an `InteractionCodeFlow`, you can call methods to make requests to the Okta IDX API. Please see the [configuration reference](#configuration-reference) section for more details.

### Create the flow

Expand All @@ -100,6 +100,12 @@ let flow = InteractionCodeFlow(
redirectUri: "<#redirectUri#>") // Must match the redirect uri in client app settings/console
```

Alternatively, if you define an `Okta.plist` configuration file within your application, you can use the default initializer to create a flow using that configuration.

```swift
let flow = try InteractionCodeFlow()
```

> **Note:** While your issuer URL may vary for advanced configurations, for most uses it will be your Okta Domain, followed by `/oauth2/default`.
### Start authenticating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import UIKit
import OktaIdx

/// Sign in controller used when initializing the signin process. This encapsulates the `IDXClient.start()` API call.
/// Sign in controller used when initializing the signin process. This encapsulates the `InteractionCodeFlow.start()` API call.
class IDXStartViewController: UIViewController, IDXSigninController {
var signin: Signin?

Expand Down
9 changes: 8 additions & 1 deletion Sources/OktaIdx/IDXFormField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ extension Remediation.Form {
///
/// Nested form values can be accessed through keyed subscripting, for example:
///
/// credentials.form["passcode"]
/// ```swift
/// remediation.form["identifier"]
/// ```
///
/// > Note: This keyed subscripting is made available through the parent ``Remediation`` object. So the above example is equally expressed as the following:
/// > ```swift
/// > remediation["identifier"]
/// > ```
public final class Field: NSObject {
/// The programmatic name for this form value.
public let name: String?
Expand Down
23 changes: 23 additions & 0 deletions Sources/OktaIdx/InteractionCodeFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ public final class InteractionCodeFlow: AuthenticationFlow {
client.add(delegate: self)
}

/// Initializer that uses the configuration defined within the application's `Okta.plist` file.
public convenience init() throws {
try self.init(try .init())
}

/// Initializer that uses the configuration defined within the given file URL.
/// - Parameter fileURL: File URL to a `plist` containing client configuration.
public convenience init(plist fileURL: URL) throws {
try self.init(try .init(plist: fileURL))
}

private convenience init(_ config: OAuth2Client.PropertyListConfiguration) throws {
guard let redirectUri = config.redirectUri else {
throw OAuth2Client.PropertyListConfigurationError.missingConfigurationValues
}

self.init(issuer: config.issuer,
clientId: config.clientId,
scopes: config.scopes,
redirectUri: redirectUri,
additionalParameters: config.additionalParameters)
}

/// Starts a new authentication session. If the client is able to successfully interact with Okta Identity Engine, a ``context-swift.property`` is assigned, and the initial ``Response`` is returned.
/// - Parameters:
/// - options: Options to include within the OAuth2 transaction.
Expand Down

0 comments on commit 4cfa3c2

Please sign in to comment.