示例#1
0
        public static async Task <AuthenticationResult> GetToken(string uniqueUserId = "")
        {
            // TODO: need to ensure that the unique user id part is included in the token cache
            var        tokenCache = TokenCacheFactory.GetTokenCache();
            OAuthToken token      = tokenCache.GetToken();

            // if there's a token but it's expired; we need to use the refresh token to get a new one
            if (token?.Expired() == true)
            {
                ExactOnlineClient client = GetClient();
                token.AccessToken       = client.GetCurrentToken(token.RefreshToken);
                token.ExpiresOnUtcTicks = client.ExpiresAt.Ticks;
                tokenCache.CacheToken(token);
            }

            AuthenticationResult authResult = ConvertAuthenticationResult(token, tokenCache);

            return(await Task.FromResult(authResult));
        }
示例#2
0
        public static ExactOnlineConnector GetConnector()
        {
            var tokenCache = TokenCacheFactory.GetTokenCache();

            if (tokenCache == null)
            {
                throw new ArgumentException("Cannot create Connector instance when the tokencache is null.");
            }

            OAuthToken token = tokenCache.GetToken();

            if (token == null || String.IsNullOrEmpty(token.UserUniqueId))
            {
                throw new ArgumentException("Cannot create Connector instance when there's no cached token or the unique user id is empty. Set a cached token.");
            }

            ExactOnlineConnector connector = new ExactOnlineConnector(token.AccessToken);

            return(connector);
        }
示例#3
0
        public static Task <Auth.AuthenticationResult> GetTokenByAuthCode(NameValueCollection callbackParams)
        {
            var    client   = GetClient();
            string token    = client.GetToken(callbackParams);
            var    userInfo = GetUserInfo(token);

            OAuthToken oauthToken = new OAuthToken()
            {
                AccessToken       = token,
                RefreshToken      = client.RefreshToken,
                ExpiresOnUtcTicks = client.ExpiresAt.Ticks,
                UserName          = userInfo.FullName,
                UserUniqueId      = userInfo.UserID
            };

            var tokenCache = TokenCacheFactory.GetTokenCache();

            tokenCache.CacheToken(oauthToken);

            var result = ConvertAuthenticationResult(oauthToken, tokenCache);

            return(Task.FromResult <Auth.AuthenticationResult>(result));
        }