Exemplo n.º 1
0
 public IAuthenticator GetAuthenticatorForAccessToken(string apiKey, string sharedSecret, TemporaryToken tempToken, string verifier)
 {
     return(OAuth1Authenticator.ForAccessToken(apiKey, sharedSecret, tempToken.OAuthToken, tempToken.OAuthTokenSecret, verifier));
 }
Exemplo n.º 2
0
    private void HandleLoginSuccess(GuestControllerResult <LogInResponse> result, Action <ILoginResult> callback)
    {
        try
        {
            LogInResponse           response          = result.Response;
            LogInData               data              = response.data;
            GuestApiErrorCollection gcErrorCollection = response.error;
            ILoginResult            loginResult       = GuestControllerErrorParser.GetLoginResult(gcErrorCollection);
            bool   flag          = false;
            string hallPassToken = string.Empty;
            string swid          = string.Empty;
            if (data != null || loginResult == null)
            {
                goto IL_015d;
            }
            if (loginResult is ILoginFailedParentalConsentResult)
            {
                foreach (GuestApiError error in gcErrorCollection.errors)
                {
                    TemporaryToken data2 = error.data;
                    if (data2 != null)
                    {
                        flag          = true;
                        hallPassToken = data2.accessToken;
                        swid          = data2.swid;
                        break;
                    }
                }
                if (flag)
                {
                    goto IL_015d;
                }
                callback(loginResult);
            }
            else
            {
                callback(loginResult);
            }
            goto end_IL_0018;
IL_015d:
            if (data == null && !flag)
            {
                if (gcErrorCollection != null)
                {
                    logger.Critical("Received unhandled error exception: " + JsonParser.ToJson(gcErrorCollection));
                }
                callback(new LoginResult(success: false, null));
            }
            else if (flag)
            {
                database.StoreSession(swid, hallPassToken, null, null, null, null, null, null, null, null, updateLastProfileRefreshTime: false, null);
                IGuestControllerClient guestControllerClient = guestControllerClientFactory.Create(swid);
                ProfileGetter.GetProfile(logger, guestControllerClient, delegate(ProfileData profileData)
                {
                    if (profileData == null)
                    {
                        database.DeleteSession(swid);
                        callback(new LoginFailedParentalConsentResult());
                    }
                    else
                    {
                        StoreSession(swid, hallPassToken, null, profileData.etag, profileData.displayName, profileData.profile);
                        HandleRefreshProfileSuccess(callback, loginResult, gcErrorCollection, profileData.profile, profileData.displayName, profileData.marketing, swid, hallPassToken);
                    }
                });
            }
            else if (!ValidateLogInData(data))
            {
                logger.Critical("Error parsing the login data:" + JsonParser.ToJson(data));
                callback(new LoginResult(success: false, null));
            }
            else
            {
                Token token = data.token;
                StoreSession(token.swid, token.access_token, token.refresh_token, data.etag, data.displayName, data.profile);
                HandleRefreshProfileSuccess(callback, loginResult, gcErrorCollection, data.profile, data.displayName, data.marketing, token.swid, token.access_token);
            }
            end_IL_0018 :;
        }
        catch (CorruptionException arg)
        {
            logger.Fatal("Corruption detected during login: "******"Unhandled exception: " + arg2);
            callback(new LoginResult(success: false, null));
        }
    }
        public PermanentToken GetPermanentTokenCredentials(string apiKey, string sharedSecret, TemporaryToken tempToken, string validator)
        {
            //consumerKey is the appKey you got when you registered your app, same for sharedSecret
            _restClient.Authenticator = _restServiceWrapper.GetAuthenticatorForAccessToken(apiKey, sharedSecret, tempToken, validator);

            RestRequest restRequest = _restServiceWrapper.GetRestRequest("oauth/access_token", Method.GET);

            IRestResponse irestResponse = _restClient.Execute(restRequest);

            var args = ParseQueryString(irestResponse.Content);

            var permanentToken = new PermanentToken
            {
                APIKey       = apiKey,
                SharedSecret = sharedSecret,
                TokenID      = args.First(x => x.Key == "oauth_token").Value,
                TokenSecret  = args.First(x => x.Key == "oauth_token_secret").Value
            };


            if (string.IsNullOrEmpty(permanentToken.TokenID) || string.IsNullOrEmpty(permanentToken.TokenSecret))
            {
                throw new NullReferenceException("Unable to retrieve permanent auth token.  Please check your credentials and try again.");
            }

            return(permanentToken);
        }