Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9083947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:53:32+00:00 2026-06-16T20:53:32+00:00

I’m new to web server programming so maybe I’m doing this the wrong way,

  • 0

I’m new to web server programming so maybe I’m doing this the wrong way, but here’s what I’m trying to do:

  1. The user authenticates using a native iOS app against the server “https://www.googleapis.com/auth/plus.me”. I’m using the ,
    GTMOAuth2 classes to handle the authorization. I’ve successfully retrieved a valid token, so this part works.

  2. I’m now trying to POST JSON data to a google-app-engine web servlet as an authenticated user by using the authentication token I obtained in step 1. Here’s the code I’m using:

    - (void)postDictionary:(NSMutableDictionary *)dict toURL:(NSMutableString *)urlString     withAuthToken:(GTMOAuth2Authentication *)authToken delegate:(id)connectDelegate
    {
    
    if( ![NSJSONSerialization isValidJSONObject:dict] )
    {
        NSLog(@"JSON Data is Invalid!");
        return;
    }
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
                                                   options:0 error:nil];
    NSMutableString *serverURL = [[NSMutableString alloc] initWithString:urlString];
    //DEBUG
    NSLog(@"sent URL: %@", serverURL);
    
    NSURL *url = [[NSURL alloc] initWithString:serverURL];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
    
    // Execute URL Asynchronously
    // Make sure we "Post" the data to the server
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:jsonData];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setValue:@"json" forHTTPHeaderField:@"Data-Type"];
    [request setValue:[NSString stringWithFormat:@"%d",
                   [jsonData length]] forHTTPHeaderField:@"Content-Length"];
    
    // We need to send the authentication information to the server.
    [request setValue:CLIENT_ID forHTTPHeaderField:@"client_id"];
    [request setValue:CLIENT_SECRET forHTTPHeaderField:@"client_secret"];
    [request setValue:authToken.accessToken forHTTPHeaderField:@"Authorization: GoogleLogin auth"];
    // Make sure we can authenticate on HTTP instead of just HTTPS
    authToken.shouldAuthorizeAllRequests=YES;   // USED FOR TESTING ON LOCALHOST ONLY!!!
    
    
    // Let's Try the Fetcher method...
    GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];
    [myFetcher setAuthorizer:authToken];
    [myFetcher beginFetchWithDelegate:self
                didFinishSelector:@selector(myFetcher:finishedWithData:error:)];
     return;
    }
    

Currently the server I’m trying to post to is is running on “http://localhost:8888/mywebapp”.

  1. On the web server, I’m trying to authenticate the user using the following java code:

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
    // Perform Authentication...
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    
    if( user != null ) {
        System.out.println("User: "+user.getNickname());
    } else {
        sendError( "You must login first!",  resp );
        return;
    }
    ...
    

The UserService never indicates a user is logged in. I’ve tried several different things, but haven’t had any success. My app just gets the “You must login first!” error message. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:53:33+00:00Added an answer on June 16, 2026 at 8:53 pm

    I solved my problem.

    1. I had to switch to the OAuth 1 protocol instead of the OAuth 2 protocol. According to the documentation I read, the OAuth 2 isn’t supported for Google App Engine yet (Does anyone know differently?). So I used the library GTM-OAUTH instead of the GTM-OAUTH2 library in my iOS app. I used the “OAuthSampleTouch” example as a basis for using the library.

    2. I needed to register my google-app-engine URL with Google, using https://accounts.google.com/managedomains.
      That gave me a ConsumerKey and ConsumerSecret I could use in my iPhone app when calling the GTM-OAUTH Library.

    3. I modified my GAE server code to use the OAUTH token:

      public void doPost(HttpServletRequest req, HttpServletResponse resp)
          throws IOException {
      // Perform Authentication...
        User user = null;
        try {
        OAuthService oathService = OAuthServiceFactory.getOAuthService();
        user = oathService.getCurrentUser();
        System.out.println("Logged in! YAY!!!");
        } catch (OAuthRequestException e) {
           System.out.println("Authentication Failed! "+e);
        }
        ...
      

    I also appended the Token into the URL, I’m not sure if this is required or not…

    Example:
    URL=”https://my-app.appspot.com/myservlet?token=XXXXXXXXXXXXXXXX”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.