smart-on-fhir / Swift-SMART

Swift SMART on FHIR framework for iOS and OS X
Other
134 stars 47 forks source link

Flow for Practitioner/Provider (User) Login #15

Closed raheelsayeed closed 6 years ago

raheelsayeed commented 6 years ago

I am working on a standalone Practitioner Login through SMART-on-FHIR.

I was wondering what was the recommended way of a Practitioner user login flow. The SMART.Client Authorization works as expected, I do get the Patient as a resource but not the Practitioner.

At the moment I extended SMART.Server to support a callback with Patient and Practitioner, but that requires some tinkering within this codebase. Is there something I'm missing?

p2 commented 6 years ago

Yeah, that's not fully supported. You should use the TokenOnly auth granularity (see https://github.com/smart-on-fhir/Swift-SMART/wiki/Client#authorization) but then you don't have a way to access the id_token that tells you which Practitioner resource to get. Would it work if you expose Client.server.auth.oauth.idToken on Client.server.idToken, then in the authorize() callback you can inspect it? If that works, happy to accept a PR!

raheelsayeed commented 6 years ago

That sounds better. I was going a long way to NOT have tokens exposed to the client. But then, I like this idea of clients resolving user resource (Patient or Practitioner or ..?) if and when necessary.

//  Server.swift
public var idToken : String? {
        get { return auth?.oauth?.idToken }
    }
// Elsewhere:
client.authorize(callback: { [unowned self] (patient,  error) in
            if let idToken = self.client.server.idToken {
                // resolve User.
            }
        })