openid / AppAuth-JS

JavaScript client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
Apache License 2.0
985 stars 161 forks source link

Benefits of this library #2

Closed sattaman closed 7 years ago

sattaman commented 7 years ago

I've got a mobile app which I've currently used oidc-client to implement auth for.

How does this library compare to oidc-client?

The owner pointed me to your project.

tikurahul commented 7 years ago

The main goal of this project is to be able to provide a standards compliant OAuth2 client for native apps written with JavaScript (Chrome Apps, Electron and Node.js client side applications).

It looks like your intended use case is React Native. What is the intended target platform (Android / iOS) ?

sattaman commented 7 years ago

Both

Sent from my iPhone

On 25 May 2017, at 17:50, Rahul Ravikumar notifications@github.com wrote:

The main goal of this project is to be able to provide a standards compliant OAuth2 client for native apps written with JavaScript (Chrome Apps, Electron and Node.js client side applications).

It looks like your intended use case is React Native. What is the intended target platform (Android / iOS) ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

iainmcgin commented 7 years ago

We don't support React Native, yet. We're working our way up to supporting more client-side JS frameworks, the library is still pretty new and it will take some time.

If you'd like to help, we'd be happy to accept contributions! You would need to implement an AuthorizationRequestHandler, AuthorizationNotifier and Requestor for React Native, calling out to the platform-specific pieces for creating an SFSafariViewController / Custom Tab as required, handling the redirect, and sending token requests. We don't have a lot of documentation to help you do this yet.

tikurahul commented 7 years ago

I think we answered your question. If you would like to reopen this issue, please let me know.

Meligy commented 7 years ago

May I ask how this is looking now? For use in web pages and/or React Native?

Thanks a lot.

tikurahul commented 7 years ago

We already support web apps. Look at the appfolder for reference. I have not made progress on the React Native side of things. Will take a look at it once I have some time 😁

Meligy commented 7 years ago

Thanks man :) :)

nmocruz commented 7 years ago

Ionic/cordova seems to be another popular framework to support to

jvirtala commented 6 years ago

Just to let you know, there is an AppAuth library for React Native now. You can find it here: https://github.com/FormidableLabs/react-native-app-auth

sattaman commented 6 years ago

fantastic :)

lostdev commented 6 years ago

@nmocruz @janiilmari Does this library support Ionic/Cordova at the moment?

Thank you!

nmocruz commented 6 years ago

@lostdev not sure, I didn't try. I'm using oidc-client-js at the moment, that has some old support to cordova. Because I'm not happy with that, I was to change to something updated.

this sample is old and I got some problem to use it, google is not accepting anymore the cordova webview

lostdev commented 6 years ago

@nmocruz exactly, I was looking for something else as well.

nmocruz commented 6 years ago

@lostdev The problem with Ionic/Cordova or hybrid apps is the webview, but possible to overwrite the browser agent, because this library seems to not do anything to show the login page in a system browser, tab etc I suspect that is not working properly.

tikurahul commented 6 years ago

If you want to use Cordova or something similar, you should* choose a wrapper to AppAuth-Android / AppAuth-iOS which is what the react-native-app-auth library does. Thanks for the link @janiilmari.

nmocruz commented 6 years ago

@tikurahul don't know what you mean with "choose a wrapper" but it seems like it's missing a plugin to cordova that code wrap AppAuth-Android and AppAuth-iOS implementations.

nmocruz commented 6 years ago

@tikurahul other is that hybrid apps in cordova easy (depends on what we use) build to andoird, ios and windows phone. Windows phone is not completely dead since that we have customers asking for it.

lostdev commented 6 years ago

@tikurahul thank you! I've been searching for a library for days and I haven't found any wrappers anywhere.

I'm at a point where I'd have to build them myself it seems, or, use a library with implicit flow using an in app browser and handle the response in a url fragment (but this would be a last resort, I know there are preferred methods).

Ultimately I'm looking for an authorization code flow that supports pixie (PKCE) in Cordova, but I can't find anything.

tikurahul commented 6 years ago

The key is to be able to launch a browser tab / system browser and to complete the authorization flow (because the user is probably already signed in) and then bring the user back to the app.

https://github.com/google/cordova-plugin-browsertab does the first part. The 2nd part is do-able by either using Intent's or using universal links in iOS. Unfortunately there are no samples I know of, that complete the flow end to end. You have a couple of choices & guidance but that's pretty much it. For react-native, there seems to be a nicely packaged library that can do everything.

Choose wisely. :smile:

lostdev commented 6 years ago

@tikurahul you had to go there didn't you... App is already built using angular so I'm stuck here :)

mraible commented 6 years ago

@lostdev Here's a tutorial I wrote that uses Ionic (with Angular) and Cordova's in-app browser to authentication with Okta. Hopefully you find it useful. https://developer.okta.com/blog/2017/08/22/build-an-ionic-app-with-user-authentication

lostdev commented 6 years ago

Hi @mraible!

Thank you for the link. Already came across your blog and actually already did a poc using your example. It was extremely helpful.

Two issues I see are that it uses the in app browser, and also doesn't support the Auth code flow, and thus didn't have a refresh token (as far as I understand).

I may try to use your approach with AppAuthJS here to see if I can do something. I won't be using Google Auth so the in app browser should work for now.

Thanks a lot for the reply!

lostdev commented 6 years ago

@tikurahul I'm having trouble understanding where the refresh token will get stored on a native device. I know it's supposed to be treated with care and cannot simply be stored in local storsge, for example, so what's the best practice? There are plugins I can use to store the token within the iOS keychain, for example.

The spec doesn't say anything about storing tokens so I'm assuming the app wouldn't store the refresh token, and instead start the Auth flow every time the app is launched. But my concern with that is that the user would need to login fairly regularly unless the idp tokens are permanent?

So much to learn!

tikurahul commented 6 years ago

Actually localStorage is a good place to store refresh tokens. It’s sandboxed to your app. On iOS you could use the keychain but localStorage is a good place to start.

One thing to remember is any storage mechanism you chose is accessible to all 3P scripts you embed. So embed only the scripts you need and choose a good CSP.

Also redirect URIs need to be protected. That’s why the web sample of AppAuth-JS uses redirection to a fragment URI (double redirect) as fragments are not available to servers logging referers.

FreeWillaert commented 6 years ago

Hi, I'm struggling with the same question - but being a Cordova noob, the road is dark... Based on what I find here and elsewhere, I consider the following, using an authorization code flow:

1/ In the Cordova app, create an AppAuth-JS AuthorizationRequest, but rather than calling performAuthorizationRequest use https://github.com/google/cordova-plugin-browsertab to redirect to the authorization server in an in-app browser tab. 2/ After authentication, redirect back to the Cordova app via a custom URI scheme and using https://github.com/EddyVerbruggen/Custom-URL-scheme so that the code ends up in the cordova app 3/ Use AppAuth-JS performTokenRequest to exchange the code for tokens.

I see some challenges for PKCE (cf https://github.com/openid/AppAuth-JS/issues/28), but overall, should this work? Am I missing something essential?

tikurahul commented 6 years ago

@FreeWillaert Your approach looks okay to me. :+1:

phiamo commented 6 years ago

has anybody successfully used this aside from https://github.com/openid/AppAuth-JS/issues/21 ?

markphillips100 commented 6 years ago

I currently use it in an Ionic app, although it has to be said the library's responsibility ends at the protocol implementation. You have to add a fair amount of functionality and plugins to make it usable. For example, how you go about handling a 401 Unauthorised to get a new access token is entirely up to the library consumer.

On Wed., 25 Apr. 2018, 8:56 am Philipp A. Mohrenweiser, < notifications@github.com> wrote:

has anybody successfully used this aside from #21 https://github.com/openid/AppAuth-JS/issues/21 ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/openid/AppAuth-JS/issues/2#issuecomment-384105330, or mute the thread https://github.com/notifications/unsubscribe-auth/AF8zNYNDsuSz7tiYTDesUI6TgzxeO84Bks5tr62WgaJpZM4NmbMv .

phiamo commented 6 years ago

Could you share your implementation ?

markphillips100 commented 6 years ago

Unfortunately not in its current form as it's part of customer funded work

On Wed., 25 Apr. 2018, 9:24 am Philipp A. Mohrenweiser, < notifications@github.com> wrote:

Could you share your implementation ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/openid/AppAuth-JS/issues/2#issuecomment-384111347, or mute the thread https://github.com/notifications/unsubscribe-auth/AF8zNVGG92SltflPLL0o7X2n3fTzrErTks5tr7Q_gaJpZM4NmbMv .

chougaard commented 6 years ago

Following the discussion in Issue 21, I've uploaded our implementation of AppAuth for Ionic. More here: https://github.com/openid/AppAuth-JS/issues/21#issuecomment-389483708

aleGuardiola commented 4 years ago

Hi, I'm struggling with the same question - but being a Cordova noob, the road is dark... Based on what I find here and elsewhere, I consider the following, using an authorization code flow:

1/ In the Cordova app, create an AppAuth-JS AuthorizationRequest, but rather than calling performAuthorizationRequest use https://github.com/google/cordova-plugin-browsertab to redirect to the authorization server in an in-app browser tab. 2/ After authentication, redirect back to the Cordova app via a custom URI scheme and using https://github.com/EddyVerbruggen/Custom-URL-scheme so that the code ends up in the cordova app 3/ Use AppAuth-JS performTokenRequest to exchange the code for tokens.

I see some challenges for PKCE (cf #28), but overall, should this work? Am I missing something essential?

@FreeWillaert I did that and worked for me thanks.

sravanpuligilla commented 4 years ago

can i get any references of react, cordova integration with OIDC