OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "google_apis/gaia/gaia_auth_fetcher.h" | 5 #include "google_apis/gaia/gaia_auth_fetcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 // Must outlive fetcher_. | 610 // Must outlive fetcher_. |
611 request_body_ = MakeClientLoginBody(username, | 611 request_body_ = MakeClientLoginBody(username, |
612 password, | 612 password, |
613 source_, | 613 source_, |
614 service, | 614 service, |
615 login_token, | 615 login_token, |
616 login_captcha, | 616 login_captcha, |
617 allow_hosted_accounts); | 617 allow_hosted_accounts); |
618 fetcher_.reset(CreateGaiaFetcher(getter_, | 618 fetcher_.reset(CreateGaiaFetcher(getter_, |
619 request_body_, | 619 request_body_, |
620 "", | 620 std::string(), |
621 client_login_gurl_, | 621 client_login_gurl_, |
622 kLoadFlagsIgnoreCookies, | 622 kLoadFlagsIgnoreCookies, |
623 this)); | 623 this)); |
624 fetch_pending_ = true; | 624 fetch_pending_ = true; |
625 fetcher_->Start(); | 625 fetcher_->Start(); |
626 } | 626 } |
627 | 627 |
628 void GaiaAuthFetcher::StartIssueAuthToken(const std::string& sid, | 628 void GaiaAuthFetcher::StartIssueAuthToken(const std::string& sid, |
629 const std::string& lsid, | 629 const std::string& lsid, |
630 const char* const service) { | 630 const char* const service) { |
631 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 631 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
632 | 632 |
633 DVLOG(1) << "Starting IssueAuthToken for: " << service; | 633 DVLOG(1) << "Starting IssueAuthToken for: " << service; |
634 requested_service_ = service; | 634 requested_service_ = service; |
635 request_body_ = MakeIssueAuthTokenBody(sid, lsid, service); | 635 request_body_ = MakeIssueAuthTokenBody(sid, lsid, service); |
636 fetcher_.reset(CreateGaiaFetcher(getter_, | 636 fetcher_.reset(CreateGaiaFetcher(getter_, |
637 request_body_, | 637 request_body_, |
638 "", | 638 std::string(), |
639 issue_auth_token_gurl_, | 639 issue_auth_token_gurl_, |
640 kLoadFlagsIgnoreCookies, | 640 kLoadFlagsIgnoreCookies, |
641 this)); | 641 this)); |
642 fetch_pending_ = true; | 642 fetch_pending_ = true; |
643 fetcher_->Start(); | 643 fetcher_->Start(); |
644 } | 644 } |
645 | 645 |
646 void GaiaAuthFetcher::StartLsoForOAuthLoginTokenExchange( | 646 void GaiaAuthFetcher::StartLsoForOAuthLoginTokenExchange( |
647 const std::string& auth_token) { | 647 const std::string& auth_token) { |
648 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 648 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
(...skipping 13 matching lines...) Expand all Loading... |
662 fetcher_->Start(); | 662 fetcher_->Start(); |
663 } | 663 } |
664 | 664 |
665 void GaiaAuthFetcher::StartRevokeOAuth2Token(const std::string& auth_token) { | 665 void GaiaAuthFetcher::StartRevokeOAuth2Token(const std::string& auth_token) { |
666 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 666 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
667 | 667 |
668 DVLOG(1) << "Starting OAuth2 token revocation"; | 668 DVLOG(1) << "Starting OAuth2 token revocation"; |
669 request_body_ = MakeRevokeTokenBody(auth_token); | 669 request_body_ = MakeRevokeTokenBody(auth_token); |
670 fetcher_.reset(CreateGaiaFetcher(getter_, | 670 fetcher_.reset(CreateGaiaFetcher(getter_, |
671 request_body_, | 671 request_body_, |
672 "", | 672 std::string(), |
673 oauth2_revoke_gurl_, | 673 oauth2_revoke_gurl_, |
674 kLoadFlagsIgnoreCookies, | 674 kLoadFlagsIgnoreCookies, |
675 this)); | 675 this)); |
676 fetch_pending_ = true; | 676 fetch_pending_ = true; |
677 fetcher_->Start(); | 677 fetcher_->Start(); |
678 } | 678 } |
679 | 679 |
680 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( | 680 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( |
681 const std::string& session_index) { | 681 const std::string& session_index) { |
682 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 682 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
683 | 683 |
684 DVLOG(1) << "Starting OAuth login token fetch with cookie jar"; | 684 DVLOG(1) << "Starting OAuth login token fetch with cookie jar"; |
685 request_body_ = MakeGetAuthCodeBody(); | 685 request_body_ = MakeGetAuthCodeBody(); |
686 | 686 |
687 std::string url = GaiaUrls::GetInstance()->client_login_to_oauth2_url(); | 687 std::string url = GaiaUrls::GetInstance()->client_login_to_oauth2_url(); |
688 if (!session_index.empty()) | 688 if (!session_index.empty()) |
689 url += "?authuser=" + session_index; | 689 url += "?authuser=" + session_index; |
690 | 690 |
691 client_login_to_oauth2_gurl_ = GURL(url); | 691 client_login_to_oauth2_gurl_ = GURL(url); |
692 | 692 |
693 fetcher_.reset(CreateGaiaFetcher(getter_, | 693 fetcher_.reset(CreateGaiaFetcher(getter_, |
694 request_body_, | 694 request_body_, |
695 "", | 695 std::string(), |
696 client_login_to_oauth2_gurl_, | 696 client_login_to_oauth2_gurl_, |
697 net::LOAD_NORMAL, | 697 net::LOAD_NORMAL, |
698 this)); | 698 this)); |
699 fetch_pending_ = true; | 699 fetch_pending_ = true; |
700 fetcher_->Start(); | 700 fetcher_->Start(); |
701 } | 701 } |
702 | 702 |
703 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( | 703 void GaiaAuthFetcher::StartAuthCodeForOAuth2TokenExchange( |
704 const std::string& auth_code) { | 704 const std::string& auth_code) { |
705 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 705 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
706 | 706 |
707 DVLOG(1) << "Starting OAuth token pair fetch"; | 707 DVLOG(1) << "Starting OAuth token pair fetch"; |
708 request_body_ = MakeGetTokenPairBody(auth_code); | 708 request_body_ = MakeGetTokenPairBody(auth_code); |
709 fetcher_.reset(CreateGaiaFetcher(getter_, | 709 fetcher_.reset(CreateGaiaFetcher(getter_, |
710 request_body_, | 710 request_body_, |
711 "", | 711 std::string(), |
712 oauth2_token_gurl_, | 712 oauth2_token_gurl_, |
713 kLoadFlagsIgnoreCookies, | 713 kLoadFlagsIgnoreCookies, |
714 this)); | 714 this)); |
715 fetch_pending_ = true; | 715 fetch_pending_ = true; |
716 fetcher_->Start(); | 716 fetcher_->Start(); |
717 } | 717 } |
718 | 718 |
719 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid) { | 719 void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid) { |
720 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 720 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
721 | 721 |
722 DVLOG(1) << "Starting GetUserInfo for lsid=" << lsid; | 722 DVLOG(1) << "Starting GetUserInfo for lsid=" << lsid; |
723 request_body_ = MakeGetUserInfoBody(lsid); | 723 request_body_ = MakeGetUserInfoBody(lsid); |
724 fetcher_.reset(CreateGaiaFetcher(getter_, | 724 fetcher_.reset(CreateGaiaFetcher(getter_, |
725 request_body_, | 725 request_body_, |
726 "", | 726 std::string(), |
727 get_user_info_gurl_, | 727 get_user_info_gurl_, |
728 kLoadFlagsIgnoreCookies, | 728 kLoadFlagsIgnoreCookies, |
729 this)); | 729 this)); |
730 fetch_pending_ = true; | 730 fetch_pending_ = true; |
731 fetcher_->Start(); | 731 fetcher_->Start(); |
732 } | 732 } |
733 | 733 |
734 void GaiaAuthFetcher::StartMergeSession(const std::string& uber_token) { | 734 void GaiaAuthFetcher::StartMergeSession(const std::string& uber_token) { |
735 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 735 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
736 | 736 |
737 DVLOG(1) << "Starting MergeSession with uber_token=" << uber_token; | 737 DVLOG(1) << "Starting MergeSession with uber_token=" << uber_token; |
738 | 738 |
739 // The continue URL is a required parameter of the MergeSession API, but in | 739 // The continue URL is a required parameter of the MergeSession API, but in |
740 // this case we don't actually need or want to navigate to it. Setting it to | 740 // this case we don't actually need or want to navigate to it. Setting it to |
741 // an arbitrary Google URL. | 741 // an arbitrary Google URL. |
742 // | 742 // |
743 // In order for the new session to be merged correctly, the server needs to | 743 // In order for the new session to be merged correctly, the server needs to |
744 // know what sessions already exist in the browser. The fetcher needs to be | 744 // know what sessions already exist in the browser. The fetcher needs to be |
745 // created such that it sends the cookies with the request, which is | 745 // created such that it sends the cookies with the request, which is |
746 // different from all other requests the fetcher can make. | 746 // different from all other requests the fetcher can make. |
747 std::string continue_url("http://www.google.com"); | 747 std::string continue_url("http://www.google.com"); |
748 request_body_ = MakeMergeSessionBody(uber_token, continue_url, source_); | 748 request_body_ = MakeMergeSessionBody(uber_token, continue_url, source_); |
749 fetcher_.reset(CreateGaiaFetcher(getter_, | 749 fetcher_.reset(CreateGaiaFetcher(getter_, |
750 request_body_, | 750 request_body_, |
751 "", | 751 std::string(), |
752 merge_session_gurl_, | 752 merge_session_gurl_, |
753 net::LOAD_NORMAL, | 753 net::LOAD_NORMAL, |
754 this)); | 754 this)); |
755 fetch_pending_ = true; | 755 fetch_pending_ = true; |
756 fetcher_->Start(); | 756 fetcher_->Start(); |
757 } | 757 } |
758 | 758 |
759 void GaiaAuthFetcher::StartTokenFetchForUberAuthExchange( | 759 void GaiaAuthFetcher::StartTokenFetchForUberAuthExchange( |
760 const std::string& access_token) { | 760 const std::string& access_token) { |
761 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 761 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
762 | 762 |
763 DVLOG(1) << "Starting StartTokenFetchForUberAuthExchange with access_token=" | 763 DVLOG(1) << "Starting StartTokenFetchForUberAuthExchange with access_token=" |
764 << access_token; | 764 << access_token; |
765 std::string authentication_header = | 765 std::string authentication_header = |
766 base::StringPrintf(kOAuthHeaderFormat, access_token.c_str()); | 766 base::StringPrintf(kOAuthHeaderFormat, access_token.c_str()); |
767 fetcher_.reset(CreateGaiaFetcher(getter_, | 767 fetcher_.reset(CreateGaiaFetcher(getter_, |
768 "", | 768 std::string(), |
769 authentication_header, | 769 authentication_header, |
770 uberauth_token_gurl_, | 770 uberauth_token_gurl_, |
771 kLoadFlagsIgnoreCookies, | 771 kLoadFlagsIgnoreCookies, |
772 this)); | 772 this)); |
773 fetch_pending_ = true; | 773 fetch_pending_ = true; |
774 fetcher_->Start(); | 774 fetcher_->Start(); |
775 } | 775 } |
776 | 776 |
777 void GaiaAuthFetcher::StartClientOAuth(const std::string& username, | 777 void GaiaAuthFetcher::StartClientOAuth(const std::string& username, |
778 const std::string& password, | 778 const std::string& password, |
779 const std::vector<std::string>& scopes, | 779 const std::vector<std::string>& scopes, |
780 const std::string& persistent_id, | 780 const std::string& persistent_id, |
781 const std::string& locale) { | 781 const std::string& locale) { |
782 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 782 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
783 | 783 |
784 request_body_ = MakeClientOAuthBody(username, password, scopes, persistent_id, | 784 request_body_ = MakeClientOAuthBody(username, password, scopes, persistent_id, |
785 source_, locale); | 785 source_, locale); |
786 fetcher_.reset(CreateGaiaFetcher(getter_, | 786 fetcher_.reset(CreateGaiaFetcher(getter_, |
787 request_body_, | 787 request_body_, |
788 "", | 788 std::string(), |
789 client_oauth_gurl_, | 789 client_oauth_gurl_, |
790 kLoadFlagsIgnoreCookies, | 790 kLoadFlagsIgnoreCookies, |
791 this)); | 791 this)); |
792 fetch_pending_ = true; | 792 fetch_pending_ = true; |
793 fetcher_->Start(); | 793 fetcher_->Start(); |
794 } | 794 } |
795 | 795 |
796 void GaiaAuthFetcher::StartClientOAuthChallengeResponse( | 796 void GaiaAuthFetcher::StartClientOAuthChallengeResponse( |
797 GoogleServiceAuthError::State type, | 797 GoogleServiceAuthError::State type, |
798 const std::string& token, | 798 const std::string& token, |
799 const std::string& solution) { | 799 const std::string& solution) { |
800 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 800 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
801 | 801 |
802 std::string name; | 802 std::string name; |
803 switch (type) { | 803 switch (type) { |
804 case GoogleServiceAuthError::CAPTCHA_REQUIRED: | 804 case GoogleServiceAuthError::CAPTCHA_REQUIRED: |
805 name = kCaptcha; | 805 name = kCaptcha; |
806 break; | 806 break; |
807 case GoogleServiceAuthError::TWO_FACTOR: | 807 case GoogleServiceAuthError::TWO_FACTOR: |
808 name = kTwoFactor; | 808 name = kTwoFactor; |
809 break; | 809 break; |
810 default: | 810 default: |
811 NOTREACHED(); | 811 NOTREACHED(); |
812 } | 812 } |
813 | 813 |
814 request_body_ = MakeClientOAuthChallengeResponseBody(name, token, solution); | 814 request_body_ = MakeClientOAuthChallengeResponseBody(name, token, solution); |
815 fetcher_.reset(CreateGaiaFetcher(getter_, | 815 fetcher_.reset(CreateGaiaFetcher(getter_, |
816 request_body_, | 816 request_body_, |
817 "", | 817 std::string(), |
818 client_oauth_gurl_, | 818 client_oauth_gurl_, |
819 kLoadFlagsIgnoreCookies, | 819 kLoadFlagsIgnoreCookies, |
820 this)); | 820 this)); |
821 fetch_pending_ = true; | 821 fetch_pending_ = true; |
822 fetcher_->Start(); | 822 fetcher_->Start(); |
823 } | 823 } |
824 | 824 |
825 void GaiaAuthFetcher::StartOAuthLogin(const std::string& access_token, | 825 void GaiaAuthFetcher::StartOAuthLogin(const std::string& access_token, |
826 const std::string& service) { | 826 const std::string& service) { |
827 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 827 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 NOTREACHED(); | 1157 NOTREACHED(); |
1158 } | 1158 } |
1159 } | 1159 } |
1160 | 1160 |
1161 // static | 1161 // static |
1162 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 1162 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
1163 const std::string& alleged_error) { | 1163 const std::string& alleged_error) { |
1164 return alleged_error.find(kSecondFactor) != | 1164 return alleged_error.find(kSecondFactor) != |
1165 std::string::npos; | 1165 std::string::npos; |
1166 } | 1166 } |
OLD | NEW |