コード例 #1
0
ファイル: TokenAuthentication.cs プロジェクト: rupe120/Nancy
        private static void RetrieveCredentials(NancyContext context, TokenAuthenticationConfiguration configuration)
        {
            var tokenFoundInHeader = true;
            var token = ExtractTokenFromHeader(context.Request);

            if (token == null)
            {
                tokenFoundInHeader = false;
                token = ExtractTokenFromCookie(context.Request);
            }

            if (token == null)
            {
                return;
            }

            var user = configuration.Tokenizer.Detokenize(token, context, configuration.UserIdentityResolver);

            if (user != null)
            {
                var tokenBasedUser = user as IUserIdentityTokenBased;
                if (tokenBasedUser != null)
                {
                    tokenBasedUser.TokenFoundInHeader = tokenFoundInHeader;
                    context.CurrentUser = tokenBasedUser;
                }
                else
                {
                    context.CurrentUser = user;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the pre request hook for loading the authenticated user's details
        /// from the auth header.
        /// </summary>
        /// <param name="configuration">Token authentication configuration to use</param>
        /// <returns>Pre request hook delegate</returns>
        private static Func <NancyContext, Response> GetCredentialRetrievalHook(TokenAuthenticationConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            return(context =>
            {
                RetrieveCredentials(context, configuration);
                return null;
            });
        }
コード例 #3
0
ファイル: TokenAuthentication.cs プロジェクト: adglopez/Nancy
        /// <summary>
        /// Gets the pre request hook for loading the authenticated user's details
        /// from the auth header.
        /// </summary>
        /// <param name="configuration">Token authentication configuration to use</param>
        /// <returns>Pre request hook delegate</returns>
        private static Func<NancyContext, Response> GetCredentialRetrievalHook(TokenAuthenticationConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            return context =>
            {
                RetrieveCredentials(context, configuration);
                return null;
            };
        }
コード例 #4
0
        private static void RetrieveCredentials(NancyContext context, TokenAuthenticationConfiguration configuration)
        {
            var token = ExtractTokenFromHeader(context.Request);

            if (token != null)
            {
                var user = configuration.Tokenizer.Detokenize(token, context);

                if (user != null)
                {
                    context.CurrentUser = user;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Enables Token authentication for the application
        /// </summary>
        /// <param name="pipelines">Pipelines to add handlers to (usually "this")</param>
        /// <param name="configuration">Forms authentication configuration</param>
        public static void Enable(IPipelines pipelines, TokenAuthenticationConfiguration configuration)
        {
            if (pipelines == null)
            {
                throw new ArgumentNullException("pipelines");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            pipelines.BeforeRequest.AddItemToStartOfPipeline(GetCredentialRetrievalHook(configuration));
        }
コード例 #6
0
ファイル: TokenAuthentication.cs プロジェクト: adglopez/Nancy
        private static void RetrieveCredentials(NancyContext context, TokenAuthenticationConfiguration configuration)
        {
            var token = ExtractTokenFromHeader(context.Request);
            if (token == null)
            {
                return;
            }

            var user = configuration.Tokenizer.Detokenize(token, context, configuration.UserIdentityResolver);
            if (user != null)
            {
                context.CurrentUser = user;
            }
        }
コード例 #7
0
ファイル: TokenAuthentication.cs プロジェクト: adglopez/Nancy
        /// <summary>
        /// Enables Token authentication for the application
        /// </summary>
        /// <param name="pipelines">Pipelines to add handlers to (usually "this")</param>
        /// <param name="configuration">Forms authentication configuration</param>
        public static void Enable(IPipelines pipelines, TokenAuthenticationConfiguration configuration)
        {
            if (pipelines == null)
            {
                throw new ArgumentNullException("pipelines");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            pipelines.BeforeRequest.AddItemToStartOfPipeline(GetCredentialRetrievalHook(configuration));
        }
コード例 #8
0
        /// <summary>
        /// Enables Token authentication for a module
        /// </summary>
        /// <param name="module">Module to add handlers to (usually "this")</param>
        /// <param name="configuration">Forms authentication configuration</param>
        public static void Enable(INancyModule module, TokenAuthenticationConfiguration configuration)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            module.RequiresAuthentication();
            module.Before.AddItemToStartOfPipeline(GetCredentialRetrievalHook(configuration));
        }
コード例 #9
0
ファイル: TokenAuthentication.cs プロジェクト: adglopez/Nancy
        /// <summary>
        /// Enables Token authentication for a module
        /// </summary>
        /// <param name="module">Module to add handlers to (usually "this")</param>
        /// <param name="configuration">Forms authentication configuration</param>
        public static void Enable(INancyModule module, TokenAuthenticationConfiguration configuration)
        {
            if (module == null)
            {
                throw new ArgumentNullException("module");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            module.RequiresAuthentication();
            module.Before.AddItemToStartOfPipeline(GetCredentialRetrievalHook(configuration));
        }