Authorization Middleware - hippogamesunity/SimpleSignIn GitHub Wiki
Platforms that implement OAuth 2.0 can return data (like auth codes) by redirecting to Redirect URI (data is returned as parameters using GET or POST). A web page where users perform sign-in is called Authorization Endpoint and the process of returning data is called OAuth Redirect.
Some platforms like Google, Apple, Microsoft or X support deep links for Redirect URI, so they can transfer auth codes directly to your app. Other platforms like Facebook or Telegram require Redirect URI to be https protocol, this means they can only return auth codes to websites. On another hand, some platforms like WebGL don't support deep linking at all. In this case we need Authorization Middleware that will handle redirect from Authorization Endpoint and forward data to your app (using deep linking or with a web request from the app when it's activated).
How does it work?
- The app creates random unique
state(which can be GUID). It will be also required for building an URL toAuthorization Endpointlater. - The app initializes
Authorization MiddlewarewithstateandredirectUri(both values are just temporary saved).redirectUriis a deep link to return data to your app (or it's empty when deep linking is not supported). - The app navigates a user to
Authorization Endpointwhere the user performs sign-in. Authorization EndpointperformsOAuth RedirecttoAuthorization Middlewareand returnsstateandcodein URL params. Some platforms may return additional data likeid_tokenor user info.Authorization Middlewarechecks ifstateis valid (was previously initialized) and performs one of the following actions:- Redirects received data with deep linking if
redirectUriis not empty (for Android, iOS, macOS, UWP and Windows). - Temporary saves received data if
redirectUriis empty (for WebGL and Editor). In this case the user is asked to return to the app manually, and the app will make a web request toAuthorization Middlewareto download data when activated.
- Redirects received data with deep linking if
Feel free to refer to our source codes. You can deploy OAuthController as a part of your ASP .NET website or use as an example to implement Authorization Middleware with other programming language.