Exemplo n.º 1
0
        static XeroApiHelper()
        {
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.json")
                         .Build();

            var apiSettings = config.GetSection("XeroApi");

            //Are you using a partner app?
            var isPartnerApp = bool.Parse(apiSettings["IsPartnerApp"]);

            // Set up some token stores to hold request and access tokens
            var accessTokenStore  = new MemoryTokenStore();
            var requestTokenStore = new MemoryTokenStore();

            // Set the application settings with an authenticator relevant to your app type
            if (isPartnerApp)
            {
                Authenticator = new PartnerMvcAuthenticator(requestTokenStore, accessTokenStore);
            }
            else
            {
                Authenticator = new PublicMvcAuthenticator(requestTokenStore, accessTokenStore);
            }
        }
Exemplo n.º 2
0
        public static IMvcAuthenticator MvcAuthenticator(XeroApiSettings applicationSettings)
        {
            if (_authenticator != null)
            {
                return(_authenticator);
            }

            // Set up some token stores to hold request and access tokens
            var accessTokenStore  = new MemoryTokenStore();
            var requestTokenStore = new MemoryTokenStore();

            // Set the application settings with an authenticator relevant to your app type
            switch (applicationSettings.AppType)
            {
            case XeroApiAppType.Public:
                _authenticator = new PublicMvcAuthenticator(requestTokenStore, accessTokenStore);
                break;

            case XeroApiAppType.Partner:
                _authenticator = new PartnerMvcAuthenticator(requestTokenStore, accessTokenStore);
                break;

            case XeroApiAppType.Private:
                throw new ApplicationException("MVC cannot be used with private applications.");

            default:
                throw new ApplicationException("Unknown app type.");
            }

            return(_authenticator);
        }
Exemplo n.º 3
0
        public static IMvcAuthenticator MvcAuthenticator(XeroApiSettings applicationSettings)
        {
            if (_authenticator != null)
            {
                return(_authenticator);
            }

            // Set up some token stores to hold request and access tokens
            var accessTokenStore  = new MemoryTokenStore();
            var requestTokenStore = new MemoryTokenStore();

            // Set the application settings with an authenticator relevant to your app type
            switch (applicationSettings.AppType.ToLower())
            {
            case "public":
                _authenticator = new PublicMvcAuthenticator(requestTokenStore, accessTokenStore);
                break;

            case "partner":
                _authenticator = new PartnerMvcAuthenticator(requestTokenStore, accessTokenStore);
                break;

            case "private":
                throw new ApplicationException("MVC cannot be used with private applications");

            case "default":
                throw new ApplicationException("AppType did not match one of: public, partner");
            }

            return(_authenticator);
        }
Exemplo n.º 4
0
        public static IMvcAuthenticator MvcAuthenticator(ApplicationSettings applicationSettings)
        {
            // Set up some token stores to hold request and access tokens
            var accessTokenStore  = new MemoryTokenStore();
            var requestTokenStore = new MemoryTokenStore();

            // Set the application settings with an authenticator relevant to your app type
            if (applicationSettings.IsPartnerApp)
            {
                Authenticator = new PartnerMvcAuthenticator(requestTokenStore, accessTokenStore);
            }
            else
            {
                Authenticator = new PublicMvcAuthenticator(requestTokenStore, accessTokenStore);
            }
            return(Authenticator);
        }
Exemplo n.º 5
0
        public HomeController(IOptions <XeroApiSettings> settings)
        {
            _user = XeroApiHelper.User();

            _authenticator = XeroApiHelper.MvcAuthenticator(settings.Value);
        }
Exemplo n.º 6
0
        public HomeController()
        {
            _user = XeroApiHelper.User();

            _authenticator = XeroApiHelper.MvcAuthenticator();
        }