OneDrive / onedrive-sdk-ios

OneDrive SDK for iOS
https://dev.onedrive.com
Other
101 stars 88 forks source link

Init ODClient with saved accessToken #187

Open mihaierosx2 opened 6 years ago

mihaierosx2 commented 6 years ago

Is there any way I can init an ODClient with a saved accessToken, that would come from an external API?

Use-case: A user has an account for an iOS app called X, with SSO benefits - Single Sign-On.

Which means: if the user logs in using the X app account on his iPad, then logs in using credentials of an OneDrive account (in the same X app, here I use the OneDriveSDK), the user should be able to be automatically get logged in with his OneDrive account credentials whenever the user uses his iPhone with the same X app account credentials.

The accessToken of OneDrive would be passed between the apps by an external API.

Basically, I am asking if there's a method (or workaround) to overwrite that ODAccountStore or something else in order to make the SDK believe the app has saved credentials in the keychain.

Any downsides of why I shouldn't do so are welcome, I can clearly see that the design of the SDK is not allowing what I intend to do.

Previously, with LiveSDK I was using:

NSArray *scopes = [NSArray arrayWithObjects:@"wl.signin",@"wl.skydrive_update",@"wl.offline_access", nil];
LiveConnectSession *session = [[LiveConnectSession alloc] initWithAccessToken:accessToken
                                                          authenticationToken:authenticationToken
                                                                 refreshToken:refreshToken
                                                                       scopes:scopes
                                                                      expires:nil];
LiveConnectClient *client = [[LiveConnectClient alloc] initWithClientId:SKYDRIVE_CLIENT_ID
                                                               delegate:nil];

client.liveClientCore.session = session;

Which worked well.

Now, what I did find similar is the method:

- (instancetype) initWithId:(NSString *)accountId
                accessToken:(NSString *)accessToken
                    expires:(NSDate *)expires
               refreshToken:(NSString *)refreshToken
                serviceInfo:(ODServiceInfo *)serviceInfo;

Which would let me create an ODAccountSession object. But there's no visible way to init the ODClient object using just a clientID and then set the session how I did it before.

Any help would be much appreciated.

mihaierosx2 commented 6 years ago

@kevklam can you take a look?