Example #1
0
        public string LoginToUri()
        {
            StopListen();
            oAuthWrapper = new DropBoxOauthClient(ApiKey, RedirectUrl);
            string state = oAuthWrapper.GetTokenToUri();

            return(state);
        }
Example #2
0
        public async Task <CloudStorageResult> InitAsync()
        {
            CloudStorageResult result = new CloudStorageResult();
            bool IsNeedLogin          = true;

            try
            {
                // 取得上次登入資訊
                LastAccessToken  = LoadAccessTokenDelegate?.Invoke();
                LastRefreshToken = LoadRefreshTokenDelegate?.Invoke();

                // 初始化
                oAuthWrapper = new DropBoxOauthClient(ApiKey, RedirectUrl);
                if (!string.IsNullOrEmpty(LastRefreshToken))  // offline 類型的 token
                {
                    IsNeedLogin = !await oAuthWrapper.RefreshTokenAsync(LastRefreshToken);

                    if (IsNeedLogin)
                    {
                        result.Status   = Status.NeedAuthenticate;
                        LastAccessToken = LastRefreshToken = null;
                    }
                    else
                    {
                        result.Status = Status.Success;
                        // 儲存新的access token/refresh token
                        SaveAccessTokenDelegate?.Invoke(oAuthWrapper.AccessToken);
                        InitDriveService();
                    }
                }
                else if (!string.IsNullOrEmpty(LastAccessToken))  // legacy 類型的 token,不需要refresh
                {
                    result.Status = Status.Success;
                    InitDriveService();
                }
                else
                {
                    // each token is empty, need login
                    result.Status  = Status.NeedAuthenticate;
                    result.Message = "Empty access and refresh token.";
                }
            }
            catch (Exception ex)
            {
                result.Status  = Status.UnknownError;
                result.Message = ex.Message;
            }
            return(result);
        }