Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private OidcClientOptions CreateOidcClientOptions(Auth0ClientOptions options)
        {
            var oidcClientOptions = new OidcClientOptions
            {
                Authority             = $"https://{options.Domain}",
                ClientId              = options.ClientId,
                ClientSecret          = options.ClientSecret,
                Scope                 = options.Scope,
                LoadProfile           = options.LoadProfile,
                Browser               = options.Browser,
                Flow                  = AuthenticationFlow.AuthorizationCode,
                ResponseMode          = AuthorizeResponseMode.Redirect,
                RedirectUri           = options.RedirectUri ?? $"https://{_options.Domain}/mobile",
                PostLogoutRedirectUri = options.PostLogoutRedirectUri ?? $"https://{_options.Domain}/mobile",

                Policy =
                {
                    RequireAuthorizationCodeHash = false,
                    RequireAccessTokenHash       = false
                }
            };

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

            if (options.BackchannelHandler != null)
            {
                oidcClientOptions.BackchannelHandler = options.BackchannelHandler;
            }

            return(oidcClientOptions);
        }
Ejemplo n.º 3
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)
            : base(options, "xamarin-ios")
        {
            options.Browser = options.Browser ?? new AutoSelectBrowser();
            var callbackUrl = $"{MainBundle.BundleIdentifier}://{options.Domain}/ios/{MainBundle.BundleIdentifier}/callback";

            options.RedirectUri           = callbackUrl;
            options.PostLogoutRedirectUri = options.PostLogoutRedirectUri ?? callbackUrl;
        }
        /// <summary>
        /// Create a new instance of <see cref="Auth0Client"/> with a given <see cref="Auth0ClientOptions"/>.
        /// </summary>
        /// <param name="options">The <see cref="Auth0ClientOptions"/> specifying the configuration to use.</param>
        /// <remarks>options.RedirectUri must match your <see cref="Activity"/> <see cref="IntentFilterPriority"/>
        /// DataScheme, DataPathPrefix and DataHost values.
        /// If not supplied it will presume the convention
        /// <code>$"{Context.PackageName}://{options.Domain}/android/{Context.PackageName}/callback".ToLower();</code>.
        /// Your <see cref="IntentFilterAttribute"/> should have DataScheme, DataPathPrefix and DataHost with values that match.
        /// Alternatively set <see cref="Auth0ClientOptions"/> RedirectUri and PostLogoutRedirectUri to match your <see cref="IntentFilterAttribute"/>.
        /// DataScheme must be lower-case or Android will not receive the callbacks.
        /// </remarks>
        public Auth0Client(Auth0ClientOptions options)
            : base(options, "xamarin-android")
        {
            var defaultRedirectUri = options.RedirectUri == null || options.PostLogoutRedirectUri == null
                ? GetConventionCallbackUri(options.Domain) : null;

            options.RedirectUri           = options.RedirectUri ?? defaultRedirectUri;
            options.PostLogoutRedirectUri = options.PostLogoutRedirectUri ?? defaultRedirectUri;
        }
Ejemplo n.º 5
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)
            : base(options, "xamarin-android")
        {
            options.Browser = options.Browser ?? new ChromeCustomTabsBrowser();
            var callbackUrl = $"{Context.PackageName}://{options.Domain}/android/{Context.PackageName}/callback".ToLower();

            options.RedirectUri           = callbackUrl;
            options.PostLogoutRedirectUri = options.PostLogoutRedirectUri ?? callbackUrl;
        }
Ejemplo n.º 6
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)
            : base(options, "xamarin-android")
        {
            options.Browser = options.Browser ?? new AutoSelectBrowser(null);
            var callbackUrl = $"{Context.PackageName}://{options.Domain}/android/{Context.PackageName}/callback";

            options.RedirectUri           = options.RedirectUri ?? callbackUrl;
            options.PostLogoutRedirectUri = options.PostLogoutRedirectUri ?? callbackUrl;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a new instance of <see cref="Auth0Client"/> with a given <see cref="Auth0ClientOptions"/> and <see cref="Context"/>.
        /// </summary>
        /// <param name="options">The <see cref="Auth0ClientOptions"/> specifying the configuration to use.</param>
        /// <param name="activity">The <see cref="Activity"/> with the <see cref="IntentFilterAttribute"/> you perform calls to <see cref="Auth0Client"/> from.</param>
        /// <remarks>options.RedirectUri must match your IntentFilter attribute's DataScheme, DataPathPrefix and DataHost values.
        /// If not supplied it will first try to detect the registered IntentFilter automatically if your supplied <paramref name="activity"/>.
        /// If it does it will presume the convention
        /// <code>$"{Context.PackageName}://{options.Domain}/android/{Context.PackageName}/callback".ToLower();</code>.
        /// Your <see cref="IntentFilter"/> attribute used to register for callbacks should have DataScheme, DataPathPrefix and DataHost with need values
        /// that match.
        /// Alternatively set the RedirectUri manually to match your IntentFilter. Please note that DataScheme should be lower-case or Android
        /// will not listen to callbacks.
        /// </remarks>
        public Auth0Client(Auth0ClientOptions options, Activity activity)
            : base(options, "xamarin-android")
        {
            options.Browser = options.Browser ?? new AutoSelectBrowser(activity);

            var defaultRedirectUri = options.RedirectUri == null || options.PostLogoutRedirectUri == null?
                                     GetActivityIntentCallbackUri(activity) ?? GetConventionCallbackUri(options.Domain) : null;

            options.RedirectUri           = options.RedirectUri ?? defaultRedirectUri;
            options.PostLogoutRedirectUri = options.PostLogoutRedirectUri ?? defaultRedirectUri;
        }
Ejemplo n.º 8
0
        private OidcClientOptions CreateOidcClientOptions(Auth0ClientOptions options)
        {
            var scopes = options.Scope.Split(' ').ToList();

            if (!scopes.Contains("openid"))
            {
                scopes.Insert(0, "openid");
            }

            var oidcClientOptions = new OidcClientOptions
            {
                Authority             = $"https://{options.Domain}",
                ClientId              = options.ClientId,
                Scope                 = String.Join(" ", scopes),
                LoadProfile           = options.LoadProfile,
                Browser               = options.Browser,
                Flow                  = AuthenticationFlow.AuthorizationCode,
                ResponseMode          = AuthorizeResponseMode.Redirect,
                RedirectUri           = options.RedirectUri ?? $"https://{_options.Domain}/mobile",
                PostLogoutRedirectUri = options.PostLogoutRedirectUri ?? $"https://{_options.Domain}/mobile",
                ClockSkew             = options.Leeway,

                Policy =
                {
                    RequireAuthorizationCodeHash = false,
                    RequireAccessTokenHash       = false
                }
            };

#pragma warning disable CS0618 // ClientSecret will be removed in a future update.
            if (!String.IsNullOrWhiteSpace(oidcClientOptions.ClientSecret))
            {
                oidcClientOptions.ClientSecret = options.ClientSecret;
            }
#pragma warning restore CS0618

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

            if (options.BackchannelHandler != null)
            {
                oidcClientOptions.BackchannelHandler = options.BackchannelHandler;
            }

            return(oidcClientOptions);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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;

            ConfigureOidcClient();
        }
Ejemplo n.º 11
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)
     : base(options, "xamarin-ios")
 {
     options.Browser     = options.Browser ?? new PlatformWebView();
     options.RedirectUri = options.RedirectUri ?? $"{MainBundle.BundleIdentifier}://{options.Domain}/ios/{MainBundle.BundleIdentifier}/callback";
 }
Ejemplo n.º 12
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)
     : base(options, "uwp")
 {
     options.Browser     = options.Browser ?? new PlatformWebView();
     options.RedirectUri = options.RedirectUri ?? WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri;
 }
Ejemplo n.º 13
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)
     : base(options, "uwp")
 {
     options.Browser = options.Browser ?? new WebViewBrowser();
 }
Ejemplo n.º 14
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)
     : base(options, "xamarin-android")
 {
     options.Browser     = options.Browser ?? new PlatformWebView();
     options.RedirectUri = $"{Context.PackageName}://{options.Domain}/android/{Context.PackageName}/callback".ToLower();
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Create a new instance of <see cref="Auth0ClientBase"/>.
 /// </summary>
 /// <param name="options"><see cref="Auth0ClientOptions"/> specifying the configuration options for this client.</param>
 /// <param name="platformName">Platform name that forms part of the user-agent when communicating with Auth0 servers.</param>
 protected Auth0ClientBase(Auth0ClientOptions options, string platformName)
 {
     _options   = options;
     _userAgent = CreateAgentString(platformName);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Create a new instance of <see cref="Auth0ClientBase"/>.
 /// </summary>
 /// <param name="options"><see cref="Auth0ClientOptions"/> specifying the configuration options for this client.</param>
 /// <param name="platformName">Platform name that forms part of the user-agent when communicating with Auth0 servers.</param>
 protected Auth0ClientBase(Auth0ClientOptions options, string platformName)
 {
     _options             = options;
     _idTokenRequirements = new IdTokenRequirements($"https://{_options.Domain}/", _options.ClientId, options.Leeway, options.MaxAge);
     _userAgent           = CreateAgentString(platformName);
 }