Skip to content

Commit

Permalink
Revert "fix: signOut never throws an error iOS (#155)"
Browse files Browse the repository at this point in the history
This reverts commit 2eeecc8.
chore: Changelog and version bump

OKTA-420627
<<<Jenkins Check-In of Tested SHA: 713340e for [email protected]>>>
Artifact: okta-react-native
Files changed count: 9
PR Link:
  • Loading branch information
oleggnidets-okta authored and eng-prod-CI-bot-okta committed Aug 16, 2021
1 parent 273b46d commit b92081f
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 216 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# 1.13.0
# 1.13.1

### Feature
### Other

- [#155](https://github.com/okta/okta-react-native/pull/155) Adds the promise for `signOut` method (iOS)
- Reverts breaking change

# 1.13.0

### Other

Expand Down
26 changes: 7 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,31 +191,19 @@ This async method will automatically redirect users to your Okta organziation fo
**Note**: on iOS there isn't a `onCancelled` event. If the sign in process is cancelled, `onError` will be triggered.

```javascript
await signInWithBrowser();
signInWithBrowser();
```

**Note**: IDP can be passed by specifying an argument with the idp parameter.

```javascript
await signInWithBrowser({ idp: 'your_idp_here' });
signInWithBrowser({ idp: 'your_idp_here' });
```

**Note**: If you want to get rid of the system sign in and sign out alert on iOS, then pass the `noSSO` parameter when calling `signInWithBrowser`. The cookies will not be retained by the browser, so after logging out the user will be prompted to re-authenticate.

```javascript
await signInWithBrowser({ noSSO: true });
```

##### Sample Usage
```javascript
signInWithBrowser({ noSSO: true })
.then(result => {
// Consume accessToken from result.access_token
})
.catch(error => {
// { code: "", message: "", detail: { message: "", status: "" } }
// handle error
})
signInWithBrowser({ noSSO: true });
```

#### `custom-sign-in`
Expand Down Expand Up @@ -269,19 +257,19 @@ componentWillUnmount() {
If you already logged in to Okta and have a valid session token, you can complete authorization by calling `authenticate` method. It will emit an event once a user successfully signs in. Make sure your event listeners are mounted and unmounted. Note: on iOS there isn't a `onCancelled` event. If the `authenticate` process is cancelled, `onError` will be triggered.

```javascript
await authenticate({sessionToken: sessionToken});
authenticate({sessionToken: sessionToken});
```

### `signOut`

Clears the browser session and the app session (stored tokens) in memory. Fires an event once a user successfully logs out. For sample usage, refer to `signIn`.
Clear the browser session and clear the app session (stored tokens) in memory. Fires an event once a user successfully logs out. For sample usage, refer to `signIn`.

**Note**: This method apply for [browser-sign-in](#browser-sign-in) scenario only. Use a combination of `revokeToken` (optional) and `clearTokens` methods to sign out when use [custom-sign-in](#custom-sign-in).
**Note**: This method apply for [browser-sign-in](#browser-sign-in) scenario only. Use a combination of `revokeToken` (optional) and `clearTokens` methods to signOut when use [custom-sign-in](#custom-sign-in).

#### browser-sign-in sample

```javascript
await signOut();
signOut();
```

#### custom-sign-in sample
Expand Down
48 changes: 8 additions & 40 deletions ios/OktaSdkBridge/OktaSdkBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import OktaOidc

// MARK: - OktaOidcProtocol

protocol OktaOidcProtocol: AnyObject {
protocol OktaOidcProtocol: class {
var configuration: OktaOidcConfig { get }

func signInWithBrowser(from presenter: UIViewController,
Expand All @@ -36,7 +36,7 @@ extension OktaOidc: OktaOidcProtocol {

// MARK: - StateManagerProtocol

protocol StateManagerProtocol: AnyObject {
protocol StateManagerProtocol: class {
var accessToken: String? { get }
var idToken: String? { get }
var refreshToken: String? { get }
Expand Down Expand Up @@ -113,20 +113,14 @@ class OktaSdkBridge: RCTEventEmitter {
}

@objc
func signIn(_ options: [String: String] = [:],
promiseResolver: @escaping RCTPromiseResolveBlock,
promiseRejecter: @escaping RCTPromiseRejectBlock) {

func signIn(_ options: [String: String] = [:]) {
guard let currOktaOidc = oktaOidc else {
let error = OktaReactNativeError.notConfigured
let errorDic = [
OktaSdkConstant.ERROR_CODE_KEY: error.errorCode,
OktaSdkConstant.ERROR_MSG_KEY: error.errorDescription
]

sendEvent(withName: OktaSdkConstant.ON_ERROR, body: errorDic)
promiseRejecter(error.errorCode, error.errorDescription, error)

return
}

Expand All @@ -136,10 +130,7 @@ class OktaSdkBridge: RCTEventEmitter {
OktaSdkConstant.ERROR_CODE_KEY: error.errorCode,
OktaSdkConstant.ERROR_MSG_KEY: error.errorDescription
]

sendEvent(withName: OktaSdkConstant.ON_ERROR, body: errorDic)
promiseRejecter(error.errorCode, error.errorDescription, error)

return
}

Expand All @@ -158,10 +149,7 @@ class OktaSdkBridge: RCTEventEmitter {
OktaSdkConstant.ERROR_CODE_KEY: OktaReactNativeError.oktaOidcError.errorCode,
OktaSdkConstant.ERROR_MSG_KEY: error.localizedDescription
]

self.sendEvent(withName: OktaSdkConstant.ON_ERROR, body: errorDic)
promiseRejecter(OktaReactNativeError.oktaOidcError.errorCode, error.localizedDescription, error)

return
}

Expand All @@ -171,38 +159,29 @@ class OktaSdkBridge: RCTEventEmitter {
OktaSdkConstant.ERROR_CODE_KEY: error.errorCode,
OktaSdkConstant.ERROR_MSG_KEY: error.errorDescription
]

self.sendEvent(withName: OktaSdkConstant.ON_ERROR, body: errorDic)
promiseRejecter(error.errorCode, error.errorDescription, error)

return
}

currStateManager.writeToSecureStorage()
let result = [
let dic = [
OktaSdkConstant.RESOLVE_TYPE_KEY: OktaSdkConstant.AUTHORIZED,
OktaSdkConstant.ACCESS_TOKEN_KEY: stateManager?.accessToken
]

self.sendEvent(withName: OktaSdkConstant.SIGN_IN_SUCCESS, body: result)
promiseResolver(result)
self.sendEvent(withName: OktaSdkConstant.SIGN_IN_SUCCESS, body: dic)
}
}

@objc
func signOut(promiseResolver: @escaping RCTPromiseResolveBlock,
promiseRejecter: @escaping RCTPromiseRejectBlock) {

func signOut() {
guard let currOktaOidc = oktaOidc else {
let error = OktaReactNativeError.notConfigured
let errorDic = [
OktaSdkConstant.ERROR_CODE_KEY: error.errorCode,
OktaSdkConstant.ERROR_MSG_KEY: error.errorDescription
]

sendEvent(withName: OktaSdkConstant.ON_ERROR, body: errorDic)
promiseRejecter(error.errorCode, error.errorDescription, error)

return
}

Expand All @@ -212,10 +191,7 @@ class OktaSdkBridge: RCTEventEmitter {
OktaSdkConstant.ERROR_CODE_KEY: error.errorCode,
OktaSdkConstant.ERROR_MSG_KEY: error.errorDescription
]

sendEvent(withName: OktaSdkConstant.ON_ERROR, body: errorDic)
promiseRejecter(error.errorCode, error.errorDescription, error)

return
}

Expand All @@ -225,10 +201,7 @@ class OktaSdkBridge: RCTEventEmitter {
OktaSdkConstant.ERROR_CODE_KEY: error.errorCode,
OktaSdkConstant.ERROR_MSG_KEY: error.errorDescription
]

sendEvent(withName: OktaSdkConstant.ON_ERROR, body: errorDic)
promiseRejecter(error.errorCode, error.errorDescription, error)

return
}

Expand All @@ -242,21 +215,16 @@ class OktaSdkBridge: RCTEventEmitter {
OktaSdkConstant.ERROR_CODE_KEY: OktaReactNativeError.oktaOidcError.errorCode,
OktaSdkConstant.ERROR_MSG_KEY: error.localizedDescription
]

self.sendEvent(withName: OktaSdkConstant.ON_ERROR, body: errorDic)
promiseRejecter(OktaReactNativeError.oktaOidcError.errorCode, error.localizedDescription, error)

return
}

let result = [
let dic = [
OktaSdkConstant.RESOLVE_TYPE_KEY: OktaSdkConstant.SIGNED_OUT
]

stateManager.clear()

self.sendEvent(withName: OktaSdkConstant.SIGN_OUT_SUCCESS, body: result)
promiseResolver(result)
self.sendEvent(withName: OktaSdkConstant.SIGN_OUT_SUCCESS, body: dic)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-Present, Okta, Inc. and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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.
Expand Down
12 changes: 3 additions & 9 deletions ios/OktaSdkBridge/ReactNativeOktaSdkBridge.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-Present, Okta, Inc. and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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.
Expand Down Expand Up @@ -27,11 +27,7 @@ @interface RCT_EXTERN_MODULE(OktaSdkBridge, RCTEventEmitter)
promiseRejecter:(RCTPromiseRejectBlock *)promiseRejecter
)

RCT_EXTERN_METHOD(
signIn:(NSDictionary*)options
promiseResolver:(RCTPromiseResolveBlock *)promiseResolver
promiseRejecter:(RCTPromiseRejectBlock *)promiseRejecter
)
RCT_EXTERN_METHOD(signIn:(NSDictionary*)options)

RCT_EXTERN_METHOD(
authenticate:
Expand All @@ -40,9 +36,7 @@ @interface RCT_EXTERN_MODULE(OktaSdkBridge, RCTEventEmitter)
promiseRejecter:(RCTPromiseRejectBlock *)promiseRejecter
)

RCT_EXTERN_METHOD(signOut:
promiseResolver:(RCTPromiseResolveBlock *)promiseResolver
promiseRejecter:(RCTPromiseRejectBlock *)promiseRejecter)
RCT_EXTERN_METHOD(signOut)

RCT_EXTERN_METHOD(getAccessToken:(RCTPromiseResolveBlock *)promiseResolver promiseRejecter:(RCTPromiseRejectBlock *)promiseRejecter)

Expand Down
12 changes: 6 additions & 6 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ PODS:
- DoubleConversion
- glog
- glog (0.3.5)
- OktaOidc (3.10.4):
- OktaOidc/AppAuth (= 3.10.4)
- OktaOidc/Okta (= 3.10.4)
- OktaOidc/AppAuth (3.10.4)
- OktaOidc/Okta (3.10.4):
- OktaOidc (3.10.1):
- OktaOidc/AppAuth (= 3.10.1)
- OktaOidc/Okta (= 3.10.1)
- OktaOidc/AppAuth (3.10.1)
- OktaOidc/Okta (3.10.1):
- OktaOidc/AppAuth
- RCTRequired (0.63.4)
- RCTTypeSafety (0.63.4):
Expand Down Expand Up @@ -350,7 +350,7 @@ SPEC CHECKSUMS:
FBReactNativeSpec: f2c97f2529dd79c083355182cc158c9f98f4bd6e
Folly: b73c3869541e86821df3c387eb0af5f65addfab4
glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
OktaOidc: 974eb5058080a91e62649022d0a1f701f9843973
OktaOidc: a768c4583eb62cb6fe93f4020e11cff48750c623
RCTRequired: 082f10cd3f905d6c124597fd1c14f6f2655ff65e
RCTTypeSafety: 8c9c544ecbf20337d069e4ae7fd9a377aadf504b
React: b0a957a2c44da4113b0c4c9853d8387f8e64e615
Expand Down
Loading

0 comments on commit b92081f

Please sign in to comment.