0

How does Oauth Work with Application URL?

I just started using Oauth and wanted to create a mobile app to work with it. When I register my Consumer Key, it asks for the Application URL where the project will reside. It also asks to verify that domain. What should I put for this if I'm using a mobile app? Does Oauth require that requests only come from this domain/URL?

Thanks,
mfet

by
1 Reply
  • QUOTE (Marvin @ Nov 2 2010, 06:43 AM) <{POST_SNAPBACK}>
    I just started using Oauth and wanted to create a mobile app to work with it. When I register my Consumer Key, it asks for the Application URL where the project will reside. It also asks to verify that domain. What should I put for this if I'm using a mobile app? Does Oauth require that requests only come from this domain/URL?

    Thanks,
    mfet



    Hi Marvin,

    1) You first need to custom application URL scheme in your info.plist file. See details at following page
    Launching Your Own Application via a Custom URL Scheme (http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html)

    Let's assume that you used "marvin" as your app URL scheme


    2) Create a web page which creates a URL that your app can handle. This URL should include all the url parameters passed to your page.

    Eg. You created a page : http://www.marvin.com/marvinapp.php

    Yahoo will call this url with some OAUTH specific parameters like http://www.marvin.com/marvinapp.php?xx=yy&aa=bb&...

    Eg code for your page :

    <?php

    $query = http_build_query($_GET);
    $url = "marvin://".$query; // important to use same scheme that you used in first step above
    echo "<html><body><h1>Go to <a href='$url'> Marvin's app </a></h1></body></html>";

    ?>

    3) Snippet of methods in app delegate class that works for me

    - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
    {
    NSString* query = [[url absoluteString] stringByReplacingOccurrencesOfString:@"myapp://" withString:@""];
    NSArray *pairs = [query componentsSeparatedByString:@"&"];
    NSMutableDictionary *response = [NSMutableDictionary dictionary];

    for (NSString *item in pairs) {
    NSArray *fields = [item componentsSeparatedByString:@"="];
    NSString *name = [fields objectAtIndex:0];
    NSString *value = [[fields objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    [response setObject:value forKey:name];
    }

    self.oauthResponse = response;

    [self createYahooSession];

    return YES;
    }

    - (void)createYahooSession
    {
    // create session with consumer key, secret and application id
    // set up a new app here: https://developer.yahoo.com/dashboard/createKey.html
    // because the default values here won't work
    self.session = [YOSSession sessionWithConsumerKey:@"your consumer key here"
    andConsumerSecret:@"your consumer secret here"
    andApplicationId:@"you app id here"];

    if(self.oauthResponse) {
    NSString *verifier = [self.oauthResponse valueForKey:@"oauth_verifier"];
    [self.session setVerifier:verifier];
    }

    BOOL hasSession = [self.session resumeSession];

    if(!hasSession) {
    [self.session sendUserToAuthorizationWithCallbackUrl:@"http://www.tusharg.com/tenthings.php"];
    } else {
    // Now you are ready to roll
    // Put here your main view controller or whatever your app starts with
    }

    return;
    }


    Let me know how it goes.
    I am currently fixing a bug that makes your application crash. It is somewhere in YOS classes :)--Yahoo
    0

Recent Posts

in OAuth General Discussion YDN SDKs