smart-on-fhir / Swift-SMART

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

I can't get authenticated #3

Closed devjamie closed 7 years ago

devjamie commented 8 years ago

Whenever I try to authorize it's giving me an invalid address error.

Here is my func

func testSomeClasses(){ print("testSomeClasses") let smart = Client( baseURL: "https://fhir-api-dstu2.smarthealthit.org", settings: [ //"client_id": "my_mobile_app", "redirect": "smartapp://callback", // must be registered ] ) print("testSomeClasses 2") smart.authProperties.embedded = true smart.authProperties.granularity = .TokenOnly // same with .PatientSelectNative print("testSomeClasses 3") smart.authorize() { patient, error in print("testSomeClasses 4") if let error = error { // there was an error print("testSomeClasses error ", error) } else { print("hello") print(patient?.name) // patient is a "Patient" resource on success, unless you've used // the TokenOnly granularity } }

}

Console prints: testSomeClasses testSomeClasses 2 testSomeClasses 3

screen shot 2016-09-14 at 4 31 39 pm

p2 commented 8 years ago

Which version/release are you using? Please set the "verbose": true flag in the settings dict as well and post the log.

devjamie commented 8 years ago

Ok I got farther, but I am now not seeing a patient in smart.authorize... thanks!

testSomeClasses [Debug] SMART: Initialized SMART on FHIR client against server https://fhir-api-dstu2.smarthealthit.org/ testSomeClasses 2 testSomeClasses 3 [Debug] SMART: ---> GET https://fhir-api-dstu2.smarthealthit.org/metadata?_summary=true [Debug] SMART: <--- 200 (404902 Byte) [Debug] SMART: Server supports REST security via “OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)” [Debug] OAuth2: Looking for items in keychain [Debug] OAuth2: Found client id [Debug] OAuth2: Initialization finished [Debug] SMART: Initialized server auth of type “authorization_code” [Debug] OAuth2: No access token, maybe I can refresh [Debug] OAuth2: I don't have a refresh token, not trying to refresh [Debug] OAuth2: Opening authorize URL in embedded Safari: https://authorize-dstu2.smarthealthit.org/authorize?client_id=a1c30470-2e49-4ca1-b0b8-a35133a9b1c8&redirect_uri=smartapp%3A%2F%2Fcallback&scope=user%2F*.*+openid+profile&response_type=code&aud=https%3A%2F%2Ffhir-api-dstu2.smarthealthit.org&state=E56338C4 smartapp://callback?code=zq8tcU&state=E56338C4

p2 commented 8 years ago

I have pushed a lot of updates:

How do those work for you now?

p2 commented 8 years ago

Arg looks like I haven't pushed develop from my home machine. Will do later today. 😬

devjamie commented 8 years ago

Ha! k thx :) 👍

p2 commented 8 years ago

You can use master in the meantime for DSTU-2 data. I've tried to minimize braking changes between master and develop (aside from the data models, obviously).

devjamie commented 8 years ago

K let you know how it goes :)

p2 commented 8 years ago

👍🏼

p2 commented 8 years ago

Turns out I hadn't actually updated Swift-SMART's develop branch. Now everything seems in order:

Hope it works for you!

firozkhan09 commented 8 years ago

same issue i am facing. Suggest any changes if need to do?

firozkhan09 commented 8 years ago

Console

[Debug] SMART: Initialized SMART on FHIR client against server https://fhir-api-dstu2.smarthealthit.org/ [Debug] SMART: ---> Optional("GET") https://fhir-api-dstu2.smarthealthit.org/metadata?_summary=true [Debug] SMART: <--- 200 (404902 Byte) [Debug] SMART: Server supports REST security via “OAuth2 using SMART-on-FHIR profile (see http://docs.smarthealthit.org)” [Debug] OAuth2: Initialization finished [Debug] OAuth2: Looking for items in keychain [Debug] OAuth2: Found client id [Debug] SMART: Initialized server auth of type “authorization_code” [Debug] OAuth2: Starting authorization [Debug] OAuth2: No access token, checking if a refresh token is available [Debug] OAuth2: I don't have a refresh token, not trying to refresh [Debug] OAuth2: Opening authorize URL embedded: https://authorize-dstu2.smarthealthit.org/authorize?redirect_uri=smartapp%3A%2F%2Fcallback&client_id=0848dec1-8b5b-4698-bb39-b2bf02c33f9e&response_type=code&aud=https%3A%2F%2Ffhir-api-dstu2.smarthealthit.org&scope=user%2F*.*+openid+profile&state=00EBC8D7

If MEDS application is installed then shows :- simulator screen shot 06-oct-2016 6 32 20 pm

if no meds application then:- simulator screen shot 06-oct-2016 6 34 02 pm

p2 commented 8 years ago

Yes, this is correct, it will redirect to the "redirect" URL that you have specified in the settings dict. Have you registered that URL scheme in your app?

firozkhan09 commented 8 years ago

No i am using demo URL

p2 commented 8 years ago

I see I need to clarify the README once back from vacation. Until then please see https://github.com/smart-on-fhir/SoF-MedList/blob/master/SoF-MedList/AppDelegate.swift (last method) on how to intercept the redirect, and register the redirect URL scheme for your app; see the sample app (Info.plist).

firozkhan09 commented 8 years ago

Thanks a lot It works i missed that

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    if smart.awaitingAuthCallback {
        return smart.didRedirect(to: url)
    }
    return false
}

to implement so its not redirecting now its working good

firozkhan09 commented 7 years ago

Thanks a lot Can you guide for refresh token. How to reconnect with refresh token Without visiting safari...

On Jan 5, 2017 5:31 AM, "Pascal Pfiffner" notifications@github.com wrote:

Closed #3 https://github.com/smart-on-fhir/Swift-SMART/issues/3 via b5c3d03 https://github.com/smart-on-fhir/Swift-SMART/commit/b5c3d034bddd5b3e02a1d2c33c4b8472a5b495b4 .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/smart-on-fhir/Swift-SMART/issues/3#event-911990449, or mute the thread https://github.com/notifications/unsubscribe-auth/ARbzYkWCgTBCf0wCruTyRLdlx8JumhiXks5rPDL1gaJpZM4J9Nqe .

p2 commented 7 years ago

The OAuth2 library that's included in this framework will do this automatically when you use the authorize call. It will:

  1. check for an access token, if it doesn't have an unexpired one
  2. check for a refresh token, if it doesn't have one or if the refresh doesn't succeed
  3. have the user sign in

Details here: https://github.com/p2/OAuth2/wiki/Call-Graph

There currently is no way to suppress the login screen, maybe this is something to take a closer look.