MacGapProject / MacGap1

Desktop WebKit wrapper for HTML/CSS/JS applications.
Other
3.55k stars 208 forks source link

How to get the URL for newly created (or redirected) page? #34

Closed mechiland closed 12 years ago

mechiland commented 12 years ago

So like most of the OAuth 2.0 links, like this:

window.open("target-oauth-2.0-url")

// You authorize it // OAuth server will redirect with special sort of "accee token" // The webview browser will actually redirect to "your-callback-url?#access_code=newly_created"

Then how do we get the url so that we can parse the access_code for later use?

liamks commented 12 years ago

In JavaScript you can access the location object. If you want the url use location.href.

mechiland commented 12 years ago

when the page is not yours, there is no way to to inject javascript to the page.

On Wed, Feb 29, 2012 at 8:20 AM, Liam Kaufman reply@reply.github.com wrote:

In JavaScript you can access the location object. If you want the url use location.href.


Reply to this email directly or view it on GitHub: https://github.com/maccman/macgap/issues/34#issuecomment-4238131

Michael Chen

Blog: http://michael.nona.name GTalk/Twitter/Facebook/Yahoo/Skype:  mechiland

liamks commented 12 years ago

I think document.referrer will get you the url of the previous page.

mechiland commented 12 years ago

Hmm...the problem is...You own neither of them. Let me make the process clearer, as of twitter OAuth example:

  1. Open up the MacGap enabled app, with local public/index.html shown up
  2. Click Auth via Twitter. MacGap calls macgap.window.open("api.twitter.com/oauth?app_id=xxx&token=yyy")
  3. You authorize the app via twitter
  4. Twitter redirect the page to another page, probably your app website URL: youapp.com?access_token=zzz
  5. Your application is hosted locally...You have to find some way to extract the access_token as you have to use this token access twitter REST API.

I had figured out a way to get the URL though it's nasty...by exposing the URL via some code like "[self.windowController.contentView.webView mainFrameURL]"

On Wed, Feb 29, 2012 at 10:37 AM, Liam Kaufman reply@reply.github.com wrote:

I think document.referrer will get you the url of the previous page.


Reply to this email directly or view it on GitHub: https://github.com/maccman/macgap/issues/34#issuecomment-4241108

Michael Chen

Blog: http://michael.nona.name GTalk/Twitter/Facebook/Yahoo/Skype:  mechiland

eliasisrael commented 9 years ago

@mechiland Did you ever find a way to do this reliably?

jeff-h commented 9 years ago

@eliasisrael Just thought I'd check that you definitely mean to be in the MacGap 1 issue queue? MacGap 2 is a complete rewrite and no further development is planned for v1.

eliasisrael commented 9 years ago

Good call, @jeff-h ; you're right that I'm trying to get this figured out for MacGap2.