Skip to content

Commit

Permalink
Merge pull request #28 from StreamAMG/release/1.2.9
Browse files Browse the repository at this point in the history
Release/1.2.9
  • Loading branch information
zachtom authored Oct 10, 2023
2 parents 9f04864 + af7fe0a commit 2db3f27
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 16 deletions.
30 changes: 30 additions & 0 deletions AuthReadme.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,36 @@ auth.getUserSummary(token: tokens.idToken) { (result: Result<UserSummaryResponse
}
```

## Logout with custom SSO

If you are using custom SSO, to logout from cloudpay, use this method to logout by passing the token you previously used to start the SSO.

```
auth.logoutWithToken(token: tokens.idToken) { (result: Result<SAResult, StreamAMGError>) in
switch result {
case .success(let status):
// Get logout status
case .failure(let error):
// Get error
}
}
```

## GetKS with custom SSO

If you are using custom SSO, then to get the user entitlements use this method. Please pass the same token you used to start the custom SSO session.

```
auth.getKSWithToken(token: tokens.idToken, entryID: "0_validEntryID") { (result: Result<(SAKSResult, String), StreamAMGError>) in
switch result {
case .success(let response):
// response.1 is the valid KS
case .failure(let error):
// error includes the reason the Key Session is not provided
}
}
```

Change Log:
===========

Expand Down
8 changes: 5 additions & 3 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ Change Log:

All notable changes to this project will be documented in this section.

### 1.2.8 - Updated MediaType APIs from POST to GET
### 1.2.9 - Updated Authentication module with new methods to logout and getKS with third party JWT tokens.

### 1.2.7 - Updated PlayKit version
### 1.2.8 - Updated Bitrate & mediaType APIs from POST to GET

### 1.2.7 - Updated PlayKit version

### 1.2.6 - Fixed an issue with CloudMatrix response

Expand All @@ -24,7 +26,7 @@ All notable changes to this project will be documented in this section.
- Default subtitle track auto-selected
- Get Label caption on subtitle selector

### 1.2.0
### 1.2.0
- Updated PlayKit module.
- Updated requirement min iOS SDK to 12+.
- Updated AMGPurchaseDelegate to include error listener when products retrieval fails
Expand Down
66 changes: 54 additions & 12 deletions Source/StreamSDKAuthentication/AuthenticationSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,50 @@ public class AuthenticationSDK {
* @param completion Completion block capturing StreamAMGUserModel or StreamAMGError
*/
public func logout(completion: ((Result<SAResult, StreamAMGError>) -> Void)?){
guard let apiURL = url else {
let error = StreamAMGError(message: "Authentication API URL not set")
guard let token = lastLoginResponse?.authenticationToken else {
let error = StreamAMGError(message: "User is not logged in")
completion?(.failure(error))
return
}
guard let token = lastLoginResponse?.authenticationToken else {
let error = StreamAMGError(message: "User is not logged in")
self.logoutWithToken(token: token, completion: completion)
}


/**
Logs out a user by sending a logout request with the provided token.

- Parameters:
- token: The authentication token for the user.
- completion: A closure to be called upon completion of the logout operation. It takes a `Result` enum as an argument, which can contain either a `.success` with a `SAResult` or a `.failure` with a `StreamAMGError`.

- Note: Make sure the `url` property is properly set before calling this method.

This function sends a logout request to the authentication API and handles the response accordingly.
*/
public func logoutWithToken(token: String, completion: ((Result<SAResult, StreamAMGError>) -> Void)?) {
// Check if the API URL is set
guard let apiURL = url else {
let error = StreamAMGError(message: "Authentication API URL not set")
completion?(.failure(error))
return
}
StreamAMGSDK.sendRequest(logoutURL(url: apiURL, token: token)){ (result: Result<LoginResponse, StreamAMGError>) in

// Send the logout request
StreamAMGSDK.sendRequest(logoutURL(url: apiURL, token: token)) { (result: Result<LoginResponse, StreamAMGError>) in
switch result {
case .success(_):
// Clear the last login response and remove stored data upon successful logout
self.lastLoginResponse = nil
self.removeStoredData()
completion?(.success(.SALogoutOK))
case .failure(let error):
// Clear the last login response and report the error in case of failure
self.lastLoginResponse = nil
completion?(.failure(error))
}
}
}



/// In order to perform queries against the CloudPay API a user must first initialise a session. This can be done for SSO users by generating a SSO Session.
Expand Down Expand Up @@ -245,21 +267,40 @@ public class AuthenticationSDK {
* @param completion Completion block capturing StreamAMGUserModel or StreamAMGError
*/
public func getKS(entryID: String, completion: ((Result<(SAKSResult, String), StreamAMGError>) -> Void)?){
guard let apiURL = url else {
let error = StreamAMGError(message: "Authentication API URL not set")
guard let token = lastLoginResponse?.authenticationToken else {
let error = StreamAMGError(message: "User is not logged in")
completion?(.failure(error))
return
}
guard let token = lastLoginResponse?.authenticationToken else {
let error = StreamAMGError(message: "User is not logged in")
self.getKSWithToken(token: token, entryID: entryID, completion: completion)
}

/**
Retrieves a Key Session (KS) for a specific entry using the provided token.

- Parameters:
- token: The authentication token for the user.
- entryID: The ID of the entry for which the KS is requested.
- completion: A closure to be called upon completion of the KS retrieval operation. It takes a `Result` enum as an argument, which can contain either a `.success` with a tuple of `SAKSResult` and the KS string or a `.failure` with a `StreamAMGError`.

- Note: Ensure that the `url` property is properly set before calling this method.

This function sends a request to retrieve a Key Session (KS) for a specific entry and handles the response accordingly.
*/
public func getKSWithToken(token: String, entryID: String, completion: ((Result<(SAKSResult, String), StreamAMGError>) -> Void)?) {
// Check if the API URL is set
guard let apiURL = url else {
let error = StreamAMGError(message: "Authentication API URL not set")
completion?(.failure(error))
return
}
StreamAMGSDK.sendRequest(ksURL(url: apiURL, entryID: entryID, token: token)){ (result: Result<LoginResponse, StreamAMGError>) in

// Send the KS retrieval request
StreamAMGSDK.sendRequest(ksURL(url: apiURL, entryID: entryID, token: token)) { (result: Result<LoginResponse, StreamAMGError>) in
switch result {
case .success(let data):
if let status = SAKSResult(rawValue: data.status ?? -2){
switch status{
if let status = SAKSResult(rawValue: data.status ?? -2) {
switch status {
case .Granted:
if let session = data.kSession {
completion?(.success((.Granted, session)))
Expand Down Expand Up @@ -287,6 +328,7 @@ public class AuthenticationSDK {
}
}
}


func securelyStoreEmailAndPass(email: String, password: String){
_ = KeyChain.store(key: "authEmail", data: email)
Expand Down
2 changes: 1 addition & 1 deletion StreamAMGSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |spec|

spec.name = "StreamAMGSDK"
spec.version = "1.2.8"
spec.version = "1.2.9"
spec.summary = "Stream AMG SDK"
spec.swift_versions = "5"

Expand Down

0 comments on commit 2db3f27

Please sign in to comment.