Holds an Octokit.User model together with the OAuth scopes that were received when the user was read.
예제 #1
0
 static IObservable <AuthenticationResult> GetAuthenticationResultForUser(UserAndScopes account)
 {
     return(Observable.Return(account == null ? AuthenticationResult.CredentialFailure
         : account == unverifiedUser
             ? AuthenticationResult.VerificationFailure
             : AuthenticationResult.Success));
 }
예제 #2
0
        IObservable <AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
        {
            return(GetAuthenticationResultForUser(userAndScopes)
                   .SelectMany(result =>
            {
                if (result.IsSuccess())
                {
                    var accountCacheItem = new AccountCacheItem(userAndScopes.User);
                    usage.IncrementLoginCount().Forget();
                    return ModelService.InsertUser(accountCacheItem).Select(_ => result);
                }

                if (result == AuthenticationResult.VerificationFailure)
                {
                    return loginCache.EraseLogin(Address).Select(_ => result);
                }
                return Observable.Return(result);
            })
                   .ObserveOn(RxApp.MainThreadScheduler)
                   .Do(result =>
            {
                if (result.IsSuccess())
                {
                    SupportsGist = userAndScopes.Scopes?.Contains("gist") ?? true;
                    IsLoggedIn = true;
                }

                log.Info("Log in from cache for login '{0}' to host '{1}' {2}",
                         userAndScopes?.User?.Login ?? "(null)",
                         hostAddress.ApiUri,
                         result.IsSuccess() ? "SUCCEEDED" : "FAILED");
            }));
        }
예제 #3
0
        IObservable<AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
        {
            return GetAuthenticationResultForUser(userAndScopes)
                .SelectMany(result =>
                {
                    if (result.IsSuccess())
                    {
                        var accountCacheItem = new AccountCacheItem(userAndScopes.User);
                        usage.IncrementLoginCount().Forget();
                        return ModelService.InsertUser(accountCacheItem).Select(_ => result);
                    }

                    if (result == AuthenticationResult.VerificationFailure)
                    {
                        return loginCache.EraseLogin(Address).Select(_ => result);
                    }
                    return Observable.Return(result);
                })
                .ObserveOn(RxApp.MainThreadScheduler)
                .Do(result =>
                {
                    if (result.IsSuccess())
                    {
                        SupportsGist = userAndScopes.Scopes?.Contains("gist") ?? true;
                        IsLoggedIn = true;
                    }

                    log.Info("Log in from cache for login '{0}' to host '{1}' {2}",
                        userAndScopes?.User?.Login ?? "(null)",
                        hostAddress.ApiUri,
                        result.IsSuccess() ? "SUCCEEDED" : "FAILED");
                });
        }
예제 #4
0
 static IObservable<AuthenticationResult> GetAuthenticationResultForUser(UserAndScopes account)
 {
     return Observable.Return(account == null ? AuthenticationResult.CredentialFailure
         : account == unverifiedUser
             ? AuthenticationResult.VerificationFailure
             : AuthenticationResult.Success);
 }
예제 #5
0
 public static AccountCacheItem Create(UserAndScopes userAndScopes)
 {
     return new AccountCacheItem(userAndScopes.User);
 }