okta/okta-auth-swift

Support for Pre and Post request delegate functionality to support Shape

seanvancity opened this issue · 6 comments

Both Shape and Okta have SDKs that are opaque to us.

Okta has a standard SDK where we ask for something at a high level, and the requests are carried out behind the scenes.

Shape has an SDK where it wants to be given the low-level request object prior to it being sent, and be handed the response for further processing after it has been received.

In order to integrate Okta with Shape, we need to grant Shape access to the requests and responses that Okta is generating.

Approach
We ask for two new callbacks to be added to the Okta SDK.

Example:

protocol OktaHttpDelegate {
    
    /// Called after request creation, just before send.
    func willSend(request: NSMutableURLRequest)
    
    /// Called after response received, just after receipt.
    func didReceive(response: HTTPURLResponse)
    
}

OktaShapeFlow

Will be repeating this issue for the iOS OIDC library and similar approach on the equivalent Android SDKs

Hi @seanvancity ,

Similar to okta/okta-oidc-ios#226, you can inject your custom URLSession into the SDK.
Example:

let unauthenticatedStatus = OktaAuthStatusUnauthenticated(oktaDomain: {YourOktaURL})
unauthenticatedStatus.restApi = OktaAPI(oktaDomain: {YourOktaURL}, urlSession: {YourCustomURLSession})
unauthenticatedStatus.authenticate(username: username,
                                           password: password ?? "",
                                           onStatusChange: onStatusChange,
                                           onError: onError)

Ildar

Hi @IldarAbdullin-okta ,

As stated above:

Shape has an SDK where it wants to be given the low-level **request** object prior to it being sent, and be handed the **response** for further processing after it has been received.

I can't find any properties on URLSession or URLSessionConfiguration, that would allow us to call a function to update each URLRequest just before it is sent and pull information off of the response just after it is received. The response capabilities are present on URLSessionTaskDelegate and similar, but URLSession doesn't allow us to assign or control those from what I see.

Do you have some ideas on how updating a request, and immediately reading from a response, might be accomplished using a custom URLSession?

Thanks,
Chris

Hi @chriswrightlulu ,

There is a way to intercept request during SSL handshake, you can fetch all active URLSessionTask objects from the current session. However if you need to modify original URLRequest this approach will not work.
Just want to double check, does Shape SDK require modification of the original request? If not then suggestion above might work

Ildar

Hi @IldarAbdullin-okta ,

Yes the Shape SDK requires modifying the request before it is sent, as the last step before send.

So it sounds like we need to try a different path.

Thanks,
Chris

Hi @chriswrightlulu ,

Looks like in that case we need to provide a way how you can inject custom HTTP client so you will be able to send requests and receive response on Application side. I will create ticket in our internal bug tracking system. I will estimate with the team and include in the plan. I will update you with the time frames

Ildar

Fixed in 2.4.0