Commit d39eb205 authored by Tomas Vik's avatar Tomas Vik
Browse files

Connecting the iOS app to local webapp

This MR contains several changes in the code replacing hardcoded `` references with using URL from config. There is a change to Transport security settings, allowing HTTP connections to `localhost:5000`. Lastly, the updated README explains the necessary steps for connecting to the local webapp.

Thank you @MadLittleMods for unblocking me with the transport security settings, saving me hours if not days of struggle.
parent e2beb47c
......@@ -2,7 +2,7 @@ import Foundation
class LoginData {
private let service = "Gitter:"
private let appSettings = TRAppSettings.sharedInstance()
private let keychain = KeychainItemWrapper(identifier: "OAuth", accessGroup: nil)
private let userDefaults = UserDefaults.standard
......@@ -37,7 +37,7 @@ class LoginData {
private func setAccessToken(_ accessToken: String) {
keychain?.setObject(service, forKey: kSecAttrService)
keychain?.setObject(appSettings!.keychainItemName(), forKey: kSecAttrService)
keychain?.setObject("OAuth", forKey: kSecAttrAccount)
keychain?.setObject(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly, forKey: kSecAttrAccessible)
keychain?.setObject(generateGTMOAuth2String(accessToken), forKey: kSecValueData)
......@@ -52,8 +52,7 @@ class LoginData {
private func generateGTMOAuth2String(_ accessToken: String) -> String {
let scope = ""
return "access_token=\(accessToken)&scope=\(urlEncode(scope))&serviceProvider=\(urlEncode(service))"
return "access_token=\(accessToken)&scope=\(urlEncode(appSettings!.oauthScope()))&serviceProvider=\(urlEncode(appSettings!.keychainItemName()))"
private func urlEncode(_ string: String) -> String {
......@@ -13,7 +13,6 @@ class LoginOauthViewController: UIViewController, WKNavigationDelegate {
private let host = ""
override func viewDidLoad() {
......@@ -69,7 +68,7 @@ class LoginOauthViewController: UIViewController, WKNavigationDelegate {
private func getAuthorisationUrl() -> URL {
var components = URLComponents(string: "\(host)/login/oauth/authorize")!
var components = URLComponents(string: "\(appSettings!.baseServerURLString()!)/login/oauth/authorize")!
var queryItems = [
URLQueryItem(name: "client_id", value: appSettings!.clientID()),
URLQueryItem(name: "redirect_uri", value: appSettings!.oauthScope()),
......@@ -100,7 +99,7 @@ class LoginOauthViewController: UIViewController, WKNavigationDelegate {
"code": code
], options: .prettyPrinted)
var request = URLRequest(url: URL(string: "\(host)/login/oauth/token")!)
var request = URLRequest(url: URL(string: "\(appSettings!.baseServerURLString()!)/login/oauth/token")!)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
request.httpMethod = "POST"
......@@ -91,5 +91,11 @@
<!-- allow connections to localhost over insecure HTTP (enables local development) -->
......@@ -6,15 +6,15 @@
<string>Gitter: </string>
......@@ -13,7 +13,7 @@ Room list | Chat view
- This app is using Swift 5
### Setup
<span id="setup"></setup>
1. Clone and setup the [`webapp`]( project
- At a very minimum, `npm install`. You don't necessarily need to run the webapp locally and can skip the Docker stuff
......@@ -26,16 +26,60 @@ Room list | Chat view
1. Open in Xcode: `open Gitter.xcworkspace`
## Run against localhost
In `Edit Scheme...` > `Arguments` > `Arguments Passed On Launch` add the following:
1. `-TroupeURL`
1. `http://localhost:5000`
1. `-TroupeWSURL`
1. `ws://localhost:5000/faye`
1. If you need to sign in, update your OAuth secrets in `Gitter/GitterSecrets-Dev.plist` with something from your local instance
## Run against local webapp
Follow the [Setup instructions](#setup) above, but compile the webapp assets by running `NODE_ENV=dev npm run build-ios-assets` in the `webapp` project. The **`dev` environment is important**.
Change the following properties in `Gitter/GitterDefaults.plist`:
<!-- the ws: means insecure protocol (as opposed to wss:) -->
*(You can paste this snippet over the current properties)*
### Set up the local OAuth
Create OAuth client for the iOS by running:
$ mongo gitter
> db.oauthclients.update(
{ clientKey: "ios-dev" },
clientKey: "ios-dev",
clientSecret: "dev-abcdef-whatevertoken123",
name: "Gitter iOS App (dev)",
tag: "ios-dev",
registeredRedirectUri: "http://localhost:5000/login/oauth/callback",
canSkipAuthorization: true
{ upsert: true }
Then you can use following snippet as `Gitter/GitterSecrets-Dev.plist`
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
## Developer and debugging notes
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment