Jump to content

Office 365 OAuth 2.0 Login to my UniGui-Hyper-Sever Application


erich.wanker

Recommended Posts

Hello,

I am looking for a solution to authenticate users via OAuth 2.0.

What exactly this should solve is the following:

A company has employees who all have an Office 365 account (the eMail addresses all end with the company domain) - the system admin said he has to share something in the Azure portal for this - so that my webapplication is allowed to create a request.

HOW can i make a OAuth 2.0 Login?

  • Only employees of the specific company should be able to log in with their account.
  • Each employee should be created as a "Restricted User" in my database when he logs in for the first time - where do I get his eMail address from?
  • What does the system admin need from me - so that he can enter everything in his Azure portal?
  • What do I need from the system admin?
  • Are there already any half-finished examples or examples for Unigui?


Thanks for help and hints
Erich

 

Link to comment
Share on other sites

hi ifgarrido,

thank you for your infos  🙂

 

Short question:

 

I have Delphi Xe4 - and i cannot open your sourccode .. .. in your code  there is unit "REST.Types" and "System.NetEncoding"... and so on

 

which version must i buy to run your demo?

https://www.embarcadero.com/app-development-tools-store/delphi

 

i hope the "Professional" Edition is enouth (1.500 € 😮 )

 

Nice greetings

Erich

 

Link to comment
Share on other sites

Hi 

I've got this example from the forum. You have to set up the application in Azure.

 

                         UniSession.Log('Got Code - see if we can get an token...');
                         http:=TNetHTTPClient.Create(Self);
                         params:=Tstringlist.Create;
                         params.Add('code=' + UniMainmodule.AzureAuthCode);
                         params.Add('client_id=' + C_client_id_Az);
//                         params.Add('client_secret=' + UriEncode(C_client_secret_Az));
                         params.Add('client_secret=' + C_client_secret_Az);
                         params.Add('scope=' + C_scope_Az);
                         params.Add('redirect_uri=' + C_redirect_uri_Az);
                         params.Add('grant_type=authorization_code');

                         Lresponse:=http.Post('https://login.microsoftonline.com/organizations/oauth2/v2.0/token', params);
                         UniSession.Log(Lresponse.ContentAsString());

                         if Lresponse.StatusText = 'OK' then
                         begin
                              token:=GetSimpleValue(Lresponse.ContentAsString, 'access_token');
                              GToken:=stringreplace (token,'"','',[rfreplaceall]);;
                              UniSession.Log(Lresponse.ContentAsString);
                              aMsg:=Lresponse.ContentAsString;


                                //set username
                               UniSession.Log('getuserInfo');
                               lresponse := http.get ('https://graph.microsoft.com/v1.0/me',nil,[TNetHeader.Create('Authorization','Bearer ' + gtoken)]);
                               if lresponse.StatusText='OK' then
                               begin
                                 UniSession.Log(Lresponse.ContentAsString);
                                 unimainmodule.AUserName := stringreplace (GetSimpleValue (lresponse.ContentAsString,'mail'),'"','',[rfreplaceall]);
                                 unimainmodule.LoginType := 2;
                               end;

                                //


                              Handled:=True;
                         end;

                        Except on E : exception do  unimainmodule.logintype := 0; // catch all unwanted exception here !

It worked for me...

Regards

Leon

 

 

logindemo.zip

  • Thanks 1
Link to comment
Share on other sites

18 hours ago, erich.wanker said:

hi ifgarrido,

thank you for your infos  🙂

 

Short question:

 

I have Delphi Xe4 - and i cannot open your sourccode .. .. in your code  there is unit "REST.Types" and "System.NetEncoding"... and so on

 

which version must i buy to run your demo?

https://www.embarcadero.com/app-development-tools-store/delphi

 

i hope the "Professional" Edition is enouth (1.500 € 😮 )

 

Nice greetings

Erich

 

I'm using Delphi Rio 10.3 Professional

But you can use Delphi Sydney 10.4 Community

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...