Example #1
0
        /// <summary>
        /// Creates a new instance of the Auth0 OIDC Client.
        /// </summary>
        /// <param name="options">The <see cref="Auth0ClientOptions"/> specifying the configuration for the Auth0 OIDC Client.</param>
        public Auth0Client(Auth0ClientOptions options)
        {
            var authority = $"https://{options.Domain}";

            var oidcClientOptions = new OidcClientOptions
            {
                Authority    = authority,
                ClientId     = options.ClientId,
                ClientSecret = options.ClientSecret,
                Scope        = options.Scope,
                LoadProfile  = options.LoadProfile,
#if __IOS__
                RedirectUri = $"{Foundation.NSBundle.MainBundle.BundleIdentifier}://callback",
                Browser     = new PlatformWebView(options.Controller),
#elif __ANDROID__
                RedirectUri = $"https://{options.Domain}/android/XamarinAndroidTestApp.XamarinAndroidTestApp/callback",
                Browser     = new PlatformWebView(options.Activity),
#else
                RedirectUri = $"https://{options.Domain}/mobile",
                Browser     = new PlatformWebView(),
#endif
                Flow         = OidcClientOptions.AuthenticationFlow.AuthorizationCode,
                ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect,
                Policy       =
                {
                    RequireAuthorizationCodeHash = false,
                    RequireAccessTokenHash       = false
                }
            };

            _oidcClient = new IdentityModel.OidcClient.OidcClient(oidcClientOptions);
        }
Example #2
0
        private void ConfigureOidcClient()
        {
            var authority = $"https://{_options.Domain}";

#if __ANDROID__
            string packageName = Android.App.Application.Context.PackageName;
#endif

            // Determine redirect uri depending on platform
#if __IOS__
            string redirectUri = $"{Foundation.NSBundle.MainBundle.BundleIdentifier}://{_options.Domain}/ios/{Foundation.NSBundle.MainBundle.BundleIdentifier}/callback";
#elif __ANDROID__
            string redirectUri = $"{packageName}://{_options.Domain}/android/{packageName}/callback".ToLower();
#elif WINDOWS_UWP
            string redirectUri = Windows.Security.Authentication.Web.WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri;
#else
            string redirectUri = $"https://{_options.Domain}/mobile";
#endif

            var oidcClientOptions = new OidcClientOptions
            {
                Authority    = authority,
                ClientId     = _options.ClientId,
                ClientSecret = _options.ClientSecret,
                Scope        = _options.Scope,
                LoadProfile  = _options.LoadProfile,
                Browser      = _options.Browser ?? new PlatformWebView(),
                Flow         = OidcClientOptions.AuthenticationFlow.AuthorizationCode,

                RedirectUri           = _options.RedirectUri ?? redirectUri,
                PostLogoutRedirectUri = _options.PostLogoutRedirectUri ?? redirectUri,

                // Set correct response mode depending on the platform
#if WINDOWS_UWP
                ResponseMode = OidcClientOptions.AuthorizeResponseMode.FormPost,
#else
                ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect,
#endif
                Policy =
                {
                    RequireAuthorizationCodeHash = false,
                    RequireAccessTokenHash       = false
                }
            };

            if (_options.RefreshTokenMessageHandler != null)
            {
                oidcClientOptions.RefreshTokenInnerHttpHandler = _options.RefreshTokenMessageHandler;
            }
            if (_options.BackchannelHandler != null)
            {
                oidcClientOptions.BackchannelHandler = _options.BackchannelHandler;
            }

            _oidcClient = new IdentityModel.OidcClient.OidcClient(oidcClientOptions);
        }
Example #3
0
        private static async Task TestOidc()
        {
            var c = new IdentityModel.OidcClient.OidcClient(new IdentityModel.OidcClient.OidcClientOptions
            {
            });
            var r = await c.LoginAsync(new IdentityModel.OidcClient.LoginRequest
            {
            });

            // call api with access_token

            await Task.CompletedTask;
        }
Example #4
0
        /// <summary>
        /// Creates a new instance of the Auth0 OIDC Client.
        /// </summary>
        /// <param name="options">The <see cref="Auth0ClientOptions"/> specifying the configuration for the Auth0 OIDC Client.</param>
        public Auth0Client(Auth0ClientOptions options)
        {
            _options = options;

            var authority = $"https://{options.Domain}";

#if __ANDROID__
            string packageName = options.Activity.Application.ApplicationInfo.PackageName;
#endif
            var oidcClientOptions = new OidcClientOptions
            {
                Authority    = authority,
                ClientId     = options.ClientId,
                ClientSecret = options.ClientSecret,
                Scope        = options.Scope,
                LoadProfile  = options.LoadProfile,
#if __IOS__
                RedirectUri = $"{Foundation.NSBundle.MainBundle.BundleIdentifier}://{options.Domain}/ios/{Foundation.NSBundle.MainBundle.BundleIdentifier}/callback",
                Browser     = new PlatformWebView(options.Controller),
#elif __ANDROID__
                RedirectUri = options.RedirectUri ?? $"{packageName}://{options.Domain}/android/{packageName}/callback".ToLower(),
                Browser     = new PlatformWebView(options.Activity),
#elif WINDOWS_UWP
                RedirectUri = Windows.Security.Authentication.Web.WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri,
                Browser     = options.Browser ?? new PlatformWebView(),
#else
                RedirectUri = options.RedirectUri ?? $"https://{options.Domain}/mobile",
                Browser     = options.Browser ?? new PlatformWebView(),
#endif
                Flow = OidcClientOptions.AuthenticationFlow.AuthorizationCode,
#if WINDOWS_UWP
                ResponseMode = OidcClientOptions.AuthorizeResponseMode.FormPost,
#else
                ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect,
#endif
                Policy =
                {
                    RequireAuthorizationCodeHash = false,
                    RequireAccessTokenHash       = false
                }
            };
            _oidcClient = new IdentityModel.OidcClient.OidcClient(oidcClientOptions);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RefreshTokenDelegatingHandler" /> class.
        /// </summary>
        /// <param name="oidcClient">The oidc client.</param>
        /// <param name="accessToken">The access token.</param>
        /// <param name="refreshToken">The refresh token.</param>
        /// <param name="innerHandler">The inner handler.</param>
        /// <exception cref="ArgumentNullException">oidcClient</exception>
        public RefreshTokenDelegatingHandler(OidcClient oidcClient, string accessToken, string refreshToken, HttpMessageHandler innerHandler = null)
        {
            _oidcClient = oidcClient ?? throw new ArgumentNullException(nameof(oidcClient));

            if (refreshToken.IsMissing())
            {
                throw new ArgumentNullException(nameof(refreshToken));
            }
            _refreshToken = refreshToken;

            if (accessToken.IsMissing())
            {
                throw new ArgumentNullException(nameof(accessToken));
            }
            _accessToken = accessToken;

            if (innerHandler != null)
            {
                InnerHandler = innerHandler;
            }
        }