<commit_before>﻿// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
namespace ServiceStack.Authentication.IdentityServer.Providers
{
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Auth;
    using Clients;
    using Interfaces;

    public class ServiceAuthProvider : IdentityServerAuthProvider
    {
        public ServiceAuthProvider(IIdentityServerAuthProviderSettings appSettings)
            : base(appSettings)
        {
        }

        public override async Task Init()
        {
            await base.Init().ConfigureAwait(false);
            if (TokenCredentialsClient == null)
                TokenCredentialsClient = new TokenCredentialsClient(AuthProviderSettings);
        }

        public ITokenCredentialsClient TokenCredentialsClient { get; set; }

        public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
        {
            var tokens = Init(authService, ref session, request);

            var reponseToken = TokenCredentialsClient.RequestToken().Result;

            if (!string.IsNullOrWhiteSpace(reponseToken.AccessToken))
            {
                tokens.AccessToken = reponseToken.AccessToken;

                session.IsAuthenticated = this.IsValidAccessToken(tokens).Result;
            }

            return OnAuthenticated(authService, session, tokens, new Dictionary<string, string>());
        }

        /// <summary>Users the Access token to request the User Info and populates the Tokens</summary>
        /// <param name="userSession">User Session</param>
        /// <param name="tokens">Tokens</param>
        /// <param name="authInfo">Authentication Info</param>
        protected override void LoadUserAuthInfo(AuthUserSession userSession, IAuthTokens tokens, Dictionary<string, string> authInfo)
        {<commit_msg>Refresh settings in ServiceAuthProvider before proceeding with authenticate call<commit_after>﻿// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
namespace ServiceStack.Authentication.IdentityServer.Providers
{
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Auth;
    using Clients;
    using Interfaces;

    public class ServiceAuthProvider : IdentityServerAuthProvider
    {
        public ServiceAuthProvider(IIdentityServerAuthProviderSettings appSettings)
            : base(appSettings)
        {
        }

        public override async Task Init()
        {
            await base.Init().ConfigureAwait(false);
            if (TokenCredentialsClient == null)
                TokenCredentialsClient = new TokenCredentialsClient(AuthProviderSettings);
        }

        public ITokenCredentialsClient TokenCredentialsClient { get; set; }

        public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
        {
            RefreshSettings();          
            var tokens = Init(authService, ref session, request);

            var reponseToken = TokenCredentialsClient.RequestToken().Result;

            if (!string.IsNullOrWhiteSpace(reponseToken.AccessToken))
            {
                tokens.AccessToken = reponseToken.AccessToken;

                session.IsAuthenticated = this.IsValidAccessToken(tokens).Result;
            }

            return OnAuthenticated(authService, session, tokens, new Dictionary<string, string>());
        }

        /// <summary>Users the Access token to request the User Info and populates the Tokens</summary>
        /// <param name="userSession">User Session</param>
        /// <param name="tokens">Tokens</param>
        /// <param name="authInfo">Authentication Info</param>
        protected override void LoadUserAuthInfo(AuthUserSession userSession, IAuthTokens tokens, Dictionary<string, string> authInfo)
        {
{'fraction_non_alphanumeric': 0.08167716917111004, 'fraction_numerical': 0.0019389238972370335, 'mean_word_length': 2.7586520947176685, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4047932', 'n_tokens_mistral': 997, 'n_tokens_neox': 985, 'n_words': 279}