Jasonette / JASONETTE-iOS

📡 Native App over HTTP, on iOS
https://www.jasonette.com
MIT License
5.26k stars 352 forks source link

Add access to the app's url scheme via API #2

Closed gliechtenstein closed 8 years ago

gliechtenstein commented 8 years ago

It would be convenient to have access to the app's URL scheme through something like $system.url_scheme (or $env.url_scheme?). Maybe we can attach more environment attributes to the same namespace going forward.

This is especially useful for running $oauth category actions for specifying redirect_uris, but I can imagine it can be used for other purposes as well.

For example instead of hardcoding options.authorize.data.redirect_uri like this:

{
  "type": "$oauth.auth",
  "options": {
    "authorize": {
      "client_id": "{{$keys.client_id}}",
      "client_secret": "{{$keys.client_secret}}",
      "scheme": "https",
      "host": "api.producthunt.com",
      "path": "/v1/oauth/authorize",
      "data": {
        "redirect_uri": "Jafd071e2f8c043611bd1595c1fdcab83c923781d://oauth",
        "response_type": "code",
        "scope": "public"
      }
    },
    "access": {
      "client_id": "{{$keys.client_id}}",
      "client_secret": "{{$keys.client_secret}}",
      "scheme": "https",
      "host": "api.producthunt.com",
      "path": "/v1/oauth/token",
      "data": {
        "grant_type": "authorization_code",
        "redirect_uri": "Jafd071e2f8c043611bd1595c1fdcab83c923781d://oauth"
      }
    }
  },
  "success": {
    "trigger": "fetch"
  }
}

It would be nice to have it replaced with:

{
  "type": "$oauth.auth",
  "options": {
    "authorize": {
      "client_id": "{{$keys.client_id}}",
      "client_secret": "{{$keys.client_secret}}",
      "scheme": "https",
      "host": "api.producthunt.com",
      "path": "/v1/oauth/authorize",
      "data": {
        "redirect_uri": "{{$system.url_scheme}}://oauth",
        "response_type": "code",
        "scope": "public"
      }
    },
    "access": {
      "client_id": "{{$keys.client_id}}",
      "client_secret": "{{$keys.client_secret}}",
      "scheme": "https",
      "host": "api.producthunt.com",
      "path": "/v1/oauth/token",
      "data": {
        "grant_type": "authorization_code",
        "redirect_uri": "{{$system.url_scheme}}://oauth"
      }
    }
  },
  "success": {
    "trigger": "fetch"
  }
}

Not sure if $system is better or $env is better. Or maybe there's a better option. Any suggestion welcome.

gliechtenstein commented 8 years ago

Fixed with https://github.com/Jasonette/JASONETTE-iOS/commit/248ccba44425be2e234753e50a08f083c4b02adf

gliechtenstein commented 8 years ago

Going with $env.