php - How to secure an authentication in swift -
i'm quite new programming apps ios. i've had deeper creating login app. procedure quite clear me have couple of concerns regarding security aspect.
a) app sending credentials provided user api can written in php. api going verify credentials , sending response app. isn't big security issue? isn't possible verify credentials has adress of api?
b) secondly haven't seen tutorial encrypts credentials in app before sending them api. if encryption let api job. proper way encrypt them in app , send encrypted credentials api? need store secret key in app?
i'm asking because proper way right beginning. thanks.
first, start saying make sure server has ssl , ipv6 functionality ready. (taking care of these right of bat, prevents app being rejected when goes app review)
in term of securing api routes, jwt token. jwt works passphrase or certificate (meaning private , public keys, think when want ssh server without password).
i'd preferred use certificates, need make sure don't lose these certificates, because once app ready sale these specific certificates allow app talk api.
once routes of api secured, i'd:
generate & store default token app's keychain (its purpose allow access api once)
from api side, create route
(/generate_token)read default token, , if valid generate new token , send response.delete default token keychain , store new token there.
when ios app first launched, have kind of isalreadyfetchedtoken = false variable saved userdefault. variable allow track if have new token or not.
if isalreadyfetchedtoken == false { // load default token variable let default_token = ... // create custom http header let header = ["authorization": "bearer \(default_token)" ] // access /generate_token route api // if response should contain new_token // save new token keychain && remove default 1 // update userdefault var true isalreadyfetchedtoken = true } now every time want access api, you'd load token keychain, , pass api routes' authorization header example [authorization: "bearer" + new_token].
this 1 way, , not way
Comments
Post a Comment