PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → OneDrive API for IOS
OneDrive API for IOS
Débuté par Mike Stewart, 05 juil. 2016 12:16 - 3 réponses
Posté le 05 juillet 2016 - 12:16
I have almost finished my project but I would really like to give it the ability to retrieve file from oneDrive as this would massively improve my final application. (I also think that this may well be a big help to others as this is kind of on the outer limits of what is described in the help files).

My understanding is that once my app is registered that the ID can then be used to allow users to log into their existing Microsoft accounts and in doing so this produces an ID token, along with certain access rights.


https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
client_id=6731de76-14a6-49ae-97bc-6eba6914391e
&response_type=code
&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F
&response_mode=query
&scope=openid%20offline_access%20https%3A%2F%2Fgraph.microsoft.com%2Fmail.read
&state=12345


This is some sample code for the request that would then forward you onto the Microsoft login.

I was considering creating a function to do the same process. Such as...

Procedure getToken(pge)
HTTPCreateForm("token")
HTTPAddParameter("token","client_id","643a9266-521b-4131-bd8b-4384bedba548")
HTTPAddParameter("token","response_type","code")
HTTPAddParameter("token","redirect_uri","urn:ietf:wg:oauth:2.0:oob")
HTTPAddParameter("token","response_mode","query")
HTTPAddParameter("token","prompt","consent")
HTTPAddParameter("token","state",pge)
HTTPAddParameter("token","scope","openid")
IF HTTPSendForm("token","https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?",httpPost)=True THEN
RESULT = (HTTPGetResult(httpResult))
END


except that the code at the top is a web address, not just something that returns a result.

There are also SDK's for all sorts of platforms such as Java or Xcode but although I can essentially see what they do I have no idea how to implement them with my WinDev project.

Any guidance or ideas would be appreciated..... Thanks
Posté le 05 juillet 2016 - 15:43
Just to add some more info on this...

I am trying essentially to get a code back from the Microsoft site. If I run the URL on a browser I get that code back in the corresponding forwarding URL. Using HTTPResult on HTTpGetREsult I get a stack of Chinese characters and using HTTPHeader I get back something different but not the code I'm after.
Posté le 06 juillet 2016 - 00:01
Hi Michael,

what you are getting with httpRequest and httpgetresult is EXACTLY what
is displayed in your browser (or a redirection to it, at worse)

The fact that you are SEEING chine character only means that you are not
working in the proper charset.

Now because you are working under IOS, there are 2 possible immediate
culprit:
- unicode vs ansi
- utf8 vs the rest of the world

Normally, everything web related is transported as ANSI. But your IOS
app is probably working in unicode by default, so an ansitounicode is
probably necessary in your code before displaying what you are getting.

Furthermore, IOS is generally preferring to work in utf8 so you may also
need to use a strategically placed utftoxxxx function...

I hope this helps

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

More information on http://www.fabriceharari.com
Posté le 06 juillet 2016 - 15:15
I converted the outgoing string to ANSI and the incoming to Unicode...

It looks like the Chinese characters were actually the HTML of the page I needed.

Now that is enabled though it is requesting that cookies be enabled.

I looked up some previous threads on this on the WINDEV forum and changed the code to the following in order to try and enable the cookies.

sCl is ANSI string = "client_id=643a9266-521b-4131-bd8b-4384bedba548"
sRT is ANSI string = "response_type = code"
sRedir is ANSI string = "redirect_uri = urn:ietf:wg:oauth:2.0:oob"
sScope is ANSI string = "scope = openid"
sU is string="https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?"

IF HTTPRequest(sU+sCl+"&"+sRT+"&"+sRedir+"&"+sScope,"Cookie: "+gsSessionId+CR,"","","","","")=True THEN
snewpage is string = (AnsiToUnicode(HTTPGetResult()))
nP is int = Length(snewpage)
RESULT=(snewpage)
ELSE
HTTPError is string = (HTTPGetResult(httpHeader))
Error(HTTPError)
END


Sadly though I am still getting the error. Anyone any ideas? I am so close to finishing this first one.....