-
Notifications
You must be signed in to change notification settings - Fork 0
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
OpenID Connect / Azure B2C PoC implementation #7
Comments
The following documents my findings and recommendations if we want to move forward with this approach. Client SDKI used the AppAuth official iOS SDK, which can be integrated with Carthage and builds for iOS and tvOS 9+. There is of course no web browser integration for tvOS, but all necessary APIs are available to implement an authentication flow (see below). The SDK provides the following features:
The SDK itself is well written, has ample documentation, unit tests and good working examples which can be configured in no time to better understand what happens under the hood. I strongly recommend to use it, though some additional work is required on our side. This work can be mitigated by delivering an updated SRG Identity framework based on AppAuth. An Android version of the framework is of course available as well. Background documentation and informationThe solution we test is Azure-based. Here is setup information for Azure B2C on iOS. As often, there is a lot of documentation and sample code, but the code is sometimes not maintained or the documentation can be misleading. For a good description of OAuth, OpenID and OpenID Connect, you can check this Stack Exchange thread. Extensive documentation about PKCE is available online, for example here, here or here. A useful playground is available to understand OAuth flows, in particular the PKCE flow. I initially thought we would need an
It is therefore likely we do not need the whole authentication flow to be implemented (in particular authentication exchange in PKCE is not needed). In fact we probably do not need PKCE at all. Client configurationThe client can be configured in two ways:
The first approach introduces an additional request and is therefore a bit slower. The choice is therefore between compactness / convenience and a slightly faster user experience. URL schemeiOS 11 introduced Prior to iOS 11, application had to use Nonetheless, a redirect URL with a custom scheme declared in the application Server configurationThe server-side required configuration is minimal:
SRG Identity integrationThe AppAuth SDK does not handle everything we need for easy integration in SRG SSR apps. I therefore recommend we keep our SRG Identity library, using AppAuth to manage all low-level authentication details. Project integrationThe AppAuth SDK supports Carthage and is therefore a perfect fit. It moreover already supports tvOS, watchOS and Catalyst, which will not prevent us from improving our SDK in the future. If we just need to manage an identity token, though, it might be superfluous to even integrate the AppAuth SDK altogether. I am not sure this is a good idea, but this is something we could at least discuss. InitializationCurrently URLs are supplied at initialization time. In the future a single SRG SSR service will handle login, therefore we should probably hide this complexity and hardcode the OpenID configuration URL (or the authorization and token URLs). Alternatively, we can provide We probably can retain the multiple service support as well if this makes sense. We currently were adding a UUID parameter to the redirect URL to match a redirect with the If this is not possible, we can stil turn our service into a singleton with a single hardcoded URL. State persistenceThe AppAuth SDK retrieves an There is no logout concept in the AppAuth SDK. To logout a user it suffices to remove the stored The OpenID configuration might apparently expose Token freshnessThe SDK manages access token freshness with a refresh token, but since we only have an identity token in our case (see above) there is no associated refresh after expiry (currently 1 hour). It is to me still unclear what the user experience will be when we actually need to renew this token. I would expect the user to have to login only very rarely, but I am not sure how this will be implemented. In any case, this should probably be a responsibility of SRG Identity. Error handlingWe should probably implement basic error handling, most notably to check if authorization code exchange delivers the expected tokens (according to my tests, if the server does not have PKCE enabled, the process does not fail but no tokens are retrieved). Either there is a way to identify such issues early (after all, the information is in the OpenID configuration file), or we should check that tokens are not Redirect URLSupporting the legacy Therefore, applications will need to declare a URL scheme even if they are compatible with iOS 12 and above only, and we will probably have to add each one of these URLs to the server whitelist so that the authentication flow can end properly. Therefore, SRG Identity will require at least one custom scheme to be defined by each application integrating it, and a different one. Each one of the associated redirect URLs will need to be addded to the server whitelist so that the authentication flow can resume properly in the correct app when the legacy approach is used. According to our OS support policy, the updated SDK will likely support iOS 12 and above. Still, if we haven't made the move from iOS 9 then, we might preserve iOS 9 support, as the work required is probably the same. This of course will be discussed within the team. Authentication warning messageThe AppAuth SDK internally chooses between In the future, this feature will not be available anymore. This is part of the now usual iOS experience and we should embrace it. Token refreshOur current SRG Identity implementation exposes a Instead, we should expose the AppAuth User account informationPreviously, user account information was retrieved with a dedicated service. With the Azure-based implementation we could test, user information is directly available within the JWT id token. Our SRG Identity library should therefore embed a JWT decoder and parse this information. Many iOS implementations exist, for example here and there, even in Objective-C. This also avoids the need for a dedicated webservice request since the token is acquired as part of the usual authentication flow. Profile pageTo be discussed. tvOS supportAccording to this AppAuth Github issue, there is no standard for authentication on tvOS, only a draft. Nonetheless, some implementations are available, see this comment in particular. I suggest we implement this missing piece in SRG Identity directly based on the existing implementation proposals above. I would rather avoid forking AppAuth for such a change, which would make updates painful afterwards. Once an official implementation is available (which will probably take some time), we will be able to drop our implementation, or to rewrite it based on the official one. |
Well, to get access and refresh tokens, it suffices to add the client id to the scope list. |
We may change our existing login provider. This issue discusses some finds and ideas for the future, provided we continue in this direction.
The text was updated successfully, but these errors were encountered: