OAuth error - Unknow Authorization header

56 views
Skip to first unread message

robert dupont

unread,
Dec 14, 2011, 6:28:20 PM12/14/11
to google-app...@googlegroups.com
Hi,
I'm trying to get the emailsettings feed with an Oauth authentication but in my web app I have the following issue : Unknow authorization header. I can retrieve an access token and the secret. But when I copy and paste these values in the Oauth playground I get the next error.
If I do all the process to obtain the access token using the playground I can retrieve a feed. But with the values retrieved with my web app no success.
I really don't know why I have this issue.

Thanks in advance for your help

Robert.

HTTP/1.1 401 Unknown authorization header
WWW-Authenticate: GoogleLogin realm="http://www.google.com/accounts/ClientLogin", service="apps"
Content-Type: text/html; charset=UTF-8
Date: Wed, 14 Dec 2011 23:20:15 GMT
Expires: Wed, 14 Dec 2011 23:20:15 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked

<?xml version="1.0"?>
<HTML>
  <HEAD>
    <TITLE>Unknown authorization header</TITLE>
  </HEAD>
  <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
    <H1>Unknown authorization header</H1>
    <H2>Error 401</H2>
  </BODY>
</HTML>

Shraddha Gupta

unread,
Dec 15, 2011, 5:16:01 AM12/15/11
to google-app...@googlegroups.com
Hello Robert,

Can you send the code where you are doing OAuth authentication?

Thanks,
Shraddha Gupta
Developer Programs Engineer
Hyderabad, Google India.



--
You received this message because you are subscribed to the Google Groups "Google Apps Domain Information and Management APIs" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-apps-mgmt-apis/-/0_El9oDUSv4J.
To post to this group, send email to google-app...@googlegroups.com.
To unsubscribe from this group, send email to google-apps-mgmt...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-apps-mgmt-apis?hl=en.

robert dupont

unread,
Dec 15, 2011, 5:38:13 AM12/15/11
to google-app...@googlegroups.com
Hi Shraddha,


Thanks for you reply,

Here is my code:
 This is my fetching request token  code (my scope : OAUTH_SCOPE = "https://apps-apis.google.com/a/feeds/emailsettings/2.0/")


      GoogleOAuthParameters  oauthParameters = new GoogleOAuthParameters();
        oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
        oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
        oauthParameters.setScope(OAUTH_SCOPE);
        oauthParameters.setOAuthCallback("http://localhost:8080/MailBoxDelegation/redirectservlet");
       
       
GoogleOAuthHelper  oauthHelper = new GoogleOAuthHelper(new OAuthHmacSha1Signer());
         oauthHelper.getUnauthorizedRequestToken(oauthParameters);
     
         String approvalPageUrl = oauthHelper.createUserAuthorizationUrl(oauthParameters);
     
            String oauth_secret = oauthParameters.getOAuthTokenSecret();
             session.setAttribute("oauth_secret",oauth_secret);
                            
            approvalPageUrl = oauthHelper.createUserAuthorizationUrl(oauthParameters);
           response.sendRedirect(approvalUrl);


The code after the redirection :

               String CONSUMER_KEY = props.getProperty("CONSUMER_KEY");
                String CONSUMER_SECRET = props.getProperty("CONSUMER_SECRET");
              
                GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
                oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
                oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
                String oauth_secret =  session.getAttribute("oauth_secret").toString();
              
OAuthHmacSha1Signer sign = new OAuthHmacSha1Signer();
  GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(sign);
oauthHelper.getOAuthParametersFromCallback(request.getQueryString(), oauthParameters);
                oauthParameters.setOAuthTokenSecret(oauth_secret);
               
           String accessToken = "";
                try {
                  accessToken = oauthHelper.getAccessToken(oauthParameters);
          
                    session.setAttribute("access_token", accessToken);
                    response.sendRedirect("delegation.jsp");
                } catch (OAuthException e) {
                logger.log(Level.SEVERE,"erreur during access token --> "+e.getMessage());
                }



the code for the creation of the service

 EmailListService service = new EmailListService(appName);
         try {
            service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
           
           
        } catch (OAuthException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

      
Here is Sthe url that I'm using to get a feed: https://apps-apis.google.com/a/feeds/emailsettings/2.0/domain/userName/delegation

I hope it will help.
just for information, I did nothing for the registration of my webapp because in the management board it was already a client name with my domain name which had access to all APIs  (I don't know if the issue comes from that)


Thanks in advance for your help

Robert

2011/12/15 Shraddha Gupta <shra...@google.com>

Gunjan Sharma

unread,
Dec 22, 2011, 3:14:20 AM12/22/11
to google-app...@googlegroups.com
Hello Robert

Here is a working code for email settings with OAuth1.0.

    GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();

    oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
    oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);
    OAuthSigner signer = new OAuthHmacSha1Signer();
    GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);
    oauthParameters.setScope(SCOPE);
    oauthHelper.getUnauthorizedRequestToken(oauthParameters);
    String requestUrl = oauthHelper.createUserAuthorizationUrl(oauthParameters);
    System.out.println(requestUrl);
    System.out.println("Please visit the URL above to authorize your OAuth "
        + "request token.  Once that is complete, press any key to "
        + "continue...");
    System.in.read();
    String token = oauthHelper.getAccessToken(oauthParameters);
    System.out.println("OAuth Access Token: " + token + " " + oauthParameters.getOAuthTokenSecret());
    System.out.println("Sending request to " + feedUrl.toString());
    System.out.println();
    GoogleService googleService =
        new GoogleService("apps", "oauth-sample-app");

    // Set the OAuth credentials which were obtained from the step above.
    googleService.setOAuthCredentials(oauthParameters, signer);

    // Make the request to Google
    BaseFeed resultFeed = googleService.getFeed(feedUrl, Feed.class);
    System.out.println("Response Data:");
    System.out.println("=====================================================");
    System.out.println("| TITLE: " + resultFeed.getEntries().size());
    if (resultFeed.getEntries().size() == 0) {
      System.out.println("|\tNo entries found.");
    } else {
      for (int i = 0; i < resultFeed.getEntries().size(); i++) {
        BaseEntry entry = (BaseEntry) resultFeed.getEntries().get(i);
        System.out.println("|\t" + (i + 1) + ": "
            + entry.getXmlBlob().getBlob());
      }
    }
    System.out.println("=====================================================");
    System.out.println();

We are still looking into why OAuth playground is not working with the same tokens. 
Reply all
Reply to author
Forward
0 new messages