Joined: Jul 2015
Posts: 24
Thanks:
2
Hi all,
How do folks --and the site's owner-- feel about native mobile clients for the website? let's say, for the review functionality at least. Maybe users who are devs can contribute? the review process appears to be service based so it looks doable.
Myself I'm an Android user but an iOS dev.
Thoughts?
Joined: Jun 2006
Posts: 4,083
Thanks:
32
I'd love to see some native mobile client for the review functionality.
In theory you can do a native front end for the flashcard reviews, but it would be limited if it relies only on the "ajax" calls. So I think the site needs a proper API, and I think some kind of private key in the user accounts that they can link to the mobile app, to authenticate themselves.
And then it would need some "syncing" functionality, so the user can review offline, and then sync their progress when they connect.
If someone's motivated enough to brainstorm the API while they build some mockup/simplified version of the client, then I will implement the API. I would otherwise rather continue with incremental improvements to the site.
There was one person who was quite motivated a couple years ago or so and willing to help me out but I was completely unmotivated then, and didn't follw up, so that is entirely my fault.
ps: I suppose, if you are sufficiently motivated, you can already build a functional mockup, that you login within a webview to have the cookies, and then work with the ajax responses from the "free review" modes (I can always document these if needed, though I think the JSON format is pretty self explanatory). If you have a client that can run the free reviews, show the example words, kanji, etc, flip the card functionality etc.. then the SRS is just a matter of adding the API, which is really the smallest part of the work. Creating a functional front end with a nice UI is a lot of work...
Joined: Jun 2006
Posts: 4,083
Thanks:
32
Well there is no authentication API. So you have to login through some kind of webkit view, which sets the "logged in cookie and the php session cookies etc", then these would have to be attached to the http requests, then the site will not see the difference whether its a client browser or an app.
I know it's possible to get cookies like that in an app, both iOS and Android. You can also design a native app that actually uses web views (html, css ,javascript), but with the ability to hook native code to the DOM events. I don't know how that works in detail though.
The better way to do it that the site doesn't have yet, is that the site gives a private key in the user settings. Your app takes the private key and username, and gives them along the http requests to authenticate the user. That also means the user doesn't need to enter their Kanji Koohii password to login in the app.
Joined: Jan 2010
Posts: 1,708
Thanks:
13
You could add OAuth if you had the time. There are quite a few libs out there that do most of the heavy lifting. OAuth 1 might be easier to put into place, though I personally like dealing with 2.0 better.
Joined: Jul 2015
Posts: 24
Thanks:
2
OK I haven't inspected much the network traffic while using the site, but my initial thoughts were that what you describe first could work (getting the session cookie and attaching it on every request), and that it wouldn't really matter for the site to see what kind of client it's talking to. I might be missing something though.
Joined: Jan 2010
Posts: 1,708
Thanks:
13
Is a library out of the question? Honestly, I wouldn't try hand rolling your own server side OAuth. I haven't looked into it but I would imagine the keys you give devs are generated from PGP/Public Key encryption.
The basics of OAuth client side are basically,
1) Get an authorization code by directing the user to authorize the app. Include app_id and redirect_url.
2) Give the server the auth code + App id + App secret.
3) Get access_token and refresh_token back.
4) Use access_token to on specified REST endpoints to get user data.
I would imagine server side would look something like.
1) Check redirect url matches app_id. Combine a timestamp and the app_id and encrypt using a server side private key to get an auth code. Redirect the user to the redirect url.
2) Take the auth code and decrypt to get the timestamp and app id. Confirm the supplied app id and secret match whats on file.
3) Generate an access token by combining a timestamp, the app secret, and maybe some other random identifier constant. Encrypt with server private key, app id, and maybe a salt? The refresh token is the same but use a different identifier so you can verify its a refresh token and not something else.
4) When you receive requests, simply decrypt the access token with your private key and verify access token is still valid and everything matches.
EDIT: The access/refresh token will also have a user id encrypted as well; something that lets you know what token goes to what user.
Mind you I've never read the actual specs on OAuth2, but I'd guess it works something like this. The encryption part is generally why you'd want a library. The libraries will just simplify all the heavy lifting of generating what you need.
Edited: 2015-08-19, 6:39 am
Joined: Jan 2010
Posts: 1,708
Thanks:
13
On Android and iOS you can register a protocol with the OS and have the app receive links from it. So if you plan to only use the app and no backend server, you can have the app tell the server the redirect url is something like "kanjiapp://mykanjiapp/auth" and the server will try to redirect there. This will trigger the registered protocol handler which points at your app and the app can then handle the rest.
Joined: Jun 2006
Posts: 4,083
Thanks:
32
@vix86 Ahh that makes sense, thanks!
@jimeux Thanks, I do not create the apps myself. So I like that OAuth lets Kanji Koohii users connect their account to a third party app without giving their password to the app. Also from what I understand the token will have a limited time so the user doesn't need to explicitly disconnect from the app if they stop using it or uninstall it.
My plan to keep things simpler first is that I will make some steps automatic. I won't create an interface for users to authorize/deauthorize individual apps. That seems over complicated, especially there may be very few Koohii apps. I will also at first ignore "scope" and basically give full access to the app. There's barely any personal information right now (email?) so I think that's fine. If I use OAuth then I guess if it becomes useful I can always use this "scope" feature to grant access to user's flashcards, while not giving access to their email, say.
Hmm in fact come to think of it the main API method to retrieve account info returns the email and I should probably remove that. Hmm.. maybe if the app uses the email to send notifications. I think I'll remove it now, easier to add later than remove it.
Joined: Jun 2006
Posts: 4,083
Thanks:
32
Ugh... seems like I'm really supposed to use SSL/TLS with OAuth2. Maybe I should use OAuth 1.
Joined: Jun 2006
Posts: 4,083
Thanks:
32
Sigh. And OAuth1 has a consumer_secret that can be found in the mobile app.
I could just consider the security "good enough", but what if the app is open source? Since porukkusu suggested the code would be publicly available, that means the consumer_secret isn't even obfuscated at all.
If someone forks the app and misuses the API (ie. stressing out the server), I need to know which is which. The consumer_secret can not be in the source code.
Joined: Jan 2010
Posts: 1,708
Thanks:
13
You can technically roll your own SSL Certificate. Only the API and Auth interface needs to done in HTTPS, although this might still throw warnings when people authorize. There are some free SSL certs out there you can use.
Joined: Jan 2010
Posts: 1,708
Thanks:
13
I haven't experimented with SSL enough to say what will happen if you use your own Cert. Generally Chrome/Firefox have a set list of cert providers that they accept signing for. An easy test for the whole thing would be to look into how to create your own cert, apply that on your server, and just create a dummy page and go there. See what Chrome/Firefox do.
But yes, users can usually skip warnings about certificate issues. The main ones that I know of are expired certs and certs that don't match the domain.