Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use Auth0 in app extensions #184

Closed
caitlinelfring opened this issue Jan 29, 2018 · 14 comments · Fixed by #365
Closed

Add ability to use Auth0 in app extensions #184

caitlinelfring opened this issue Jan 29, 2018 · 14 comments · Fixed by #365

Comments

@caitlinelfring
Copy link

In Apple's Developer Docs, UIApplication.shared isn't available to app extensions: https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionOverview.html#//apple_ref/doc/uid/TP40014214-CH2-SW6

The Auth0 library accesses this here:

return UIApplication.shared.keyWindow?.rootViewController

Can you find a way to make your library usable in app extensions?

@cocojoe
Copy link
Member

cocojoe commented Feb 7, 2018

This is not something we support and is not in our plans, I have not looked at it in great detail so do not know what is possible. However, if you wish to fork the repo and try out some ideas, I would be interested to see the results.

@cocojoe
Copy link
Member

cocojoe commented May 22, 2018

Closing, inactivity.

@cocojoe cocojoe closed this as completed May 22, 2018
@mrrhysbutler
Copy link

Just to chime in here, we too are currently integrating auth0 into a notification extension. We get warning:

ld: warning: linking against a dylib which is not safe for use in application extensions

on both Auth0 and SimpleKeychain libs.

Our use case is: notification extension needs to access API in background, almost certainly, we need to refresh access token as part of accessing private API. The funny thing is, we are doing this currently (sharing credentials using shared keychain and SimpleKeychain to share refresh token from main app) and things are working great, but all guidance we have had in the past is that apple rejects apps for using libraries with warnings such as this.

It's a shame because I know other swift dependencies are able to support extensions, (I think we can use @available iOSApplicationExtension possibly?) but if supporting extensions via the API is not currently in the pipeline, would you suggest token refresh simply by using HTTP directly as described in the auth0 docs like this: https://auth0.com/docs/tokens/refresh-token/current ?

@cocojoe
Copy link
Member

cocojoe commented Aug 8, 2018

@mrrhysbutler it's not a focus for us. However, if you get it working please raise a PR be happy to review.

@caitlinelfring
Copy link
Author

@mrrhysbutler I'm not sure if this will help, but to workaround this issue, I ended up just using the old Lock.swift API client (pod 'Lock/Core', '~> 1.29.1') within the app extension to renew tokens and storing them in the shared keychain. Not an ideal solution since this version likely isn't supported anymore

@mrrhysbutler
Copy link

Thanks @caitlin615 for the suggestion, and @cocojoe for the feedback.

@andrew-locklair
Copy link

Hi, I understand the issue is closed, but it seems that this approach might work to allow Auth0 to be used as a Pod in app extensions. Anywhere UIApplication.shared is used, we may be able to use this instead:

let application = UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication

Of course, that means that some items that depend on UIApplication.shared returning something won't work, since it returns nil in an app extension. But at least we can use the credential gathering portions of Auth0 if we're already logged in.

@Widcket
Copy link
Contributor

Widcket commented Mar 5, 2020

@caitlin615 and all, we revisited this and got an implementation in the feature/extensions-support branch. It doesn't support WebAuth, so it can only be used as an API Client + Credentials manager. Can you try it out and see if it works for you?

@Widcket Widcket reopened this Mar 5, 2020
@andrew-locklair
Copy link

andrew-locklair commented Mar 5, 2020

@Widcket This looks quite promising. Apologies for dumb question - Is there a way I can integrate this and get the WebAuth working in my main target while allowing the credentials manager to work in the extensions?

@Widcket
Copy link
Contributor

Widcket commented Mar 6, 2020

@xparabolax yes, you can use the credentials manager in the extensions while using WebAuth in the app.

@andrew-locklair
Copy link

@Widcket I have in my Podfile these lines:

target 'MainApp' do
  use_frameworks!

  ...

  pod 'Auth0', :git => 'https://github.com/auth0/Auth0.swift.git', :branch => 'feature/extensions-support'
end

target 'Extension' do
  use_frameworks!

  ...

  pod 'Auth0', :git => 'https://github.com/auth0/Auth0.swift.git', :branch => 'feature/extensions-support'
end

When I pod install for this Podfile, my authentication class cannot resolve Auth0.webAuth even though it is only a member of my MainApp target. It provides the error Module 'Auth0' has no member named 'webAuth'.

@Widcket
Copy link
Contributor

Widcket commented Mar 6, 2020

@xparabolax I went with a runtime check instead of a flag. Can you give it a try please?

@andrew-locklair
Copy link

@Widcket That did it! It works perfectly for me. Thank you so much!

@Widcket
Copy link
Contributor

Widcket commented Mar 30, 2020

This is now out in the 1.23.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants