Пример #1
0
 public void TokenFetchComplete(ZToken AccessToken, UserData userData)
 {
     Debug.WriteLine("Hii");
 }
Пример #2
0
        /// <summary>To get oauth token from library for the current user/></summary>
        /// <returns>OAuth token for the current user/></returns>
        public static async Task <string> GetAuthTokenAsync(string zuid, bool updateSSOCurrentUser = true) // TODO: Change it to GetOAuthAsync()
        {
            string oAuthToken = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(zuid))
                {
                    UserData userData = null;
                    try
                    {
                        userData = IAMSSOKit.GetUserData(zuid, updateSSOCurrentUser);
                    }
                    catch (Exception ex)
                    {
                        //Logger.Error(LogManager.GetCallerInfo(), "While getting oAuth UserData is null for ZUID: {0}", new object[] { zuid });
                        throw ex;
                    }

                    if (userData != null)
                    {
                        ZToken token = await userData.GetTokenAsync().ConfigureAwait(false);

                        if (token.Status == ZSSOErrorCodes.ok)
                        {
                            oAuthToken = token.Token;
                        }
                        else if (token.Status == ZSSOErrorCodes.invalidMobileCode)
                        {
                            // Invalid session
                            bool isLogOutSuccess = await userData.LogoutAndRemoveAsync();

                            if (isLogOutSuccess)
                            {
                                lock (LogOutHandledLock)
                                {
                                    if (!LogOutHandled.ContainsKey(zuid))
                                    {
                                        LogOutHandled.Add(zuid, false);
                                        //CommonNotifications.NotifyUserLoggedOut(zuid);
                                    }
                                }
                            }
                            else
                            {
                                throw new Exception("Failed to logout");
                            }
                        }
                        else
                        {
                            throw token.Exception;
                        }
                    }
                    else
                    {
                        lock (LogOutHandledLock)
                        {
                            if (!LogOutHandled.ContainsKey(zuid))
                            {
                                LogOutHandled.Add(zuid, false);
                                //CommonNotifications.NotifyUserLoggedOut(zuid);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Logger.Fatal(LogManager.GetCallerInfo(), "Error in retreiving oAuth token for ZUID: {0}. Exception: {1}", new object[] { zuid, ex.Message });
                throw ex;
            }

            return(oAuthToken);
        }