erich.wanker Posted November 27, 2022 Share Posted November 27, 2022 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 Quote Link to comment Share on other sites More sharing options...
lfgarrido Posted November 28, 2022 Share Posted November 28, 2022 First, you have to create an application at Azure to get CLIENT ID and CLIENT SECRET I have had successful tests with that and I could send emails using Indy and Rest native components for Office 365 OAuth2 protocol https://github.com/lfgarrido/uniOffice365 Quote Link to comment Share on other sites More sharing options...
erich.wanker Posted November 28, 2022 Author Share Posted November 28, 2022 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 Quote Link to comment Share on other sites More sharing options...
leons Posted November 28, 2022 Share Posted November 28, 2022 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 1 Quote Link to comment Share on other sites More sharing options...
lfgarrido Posted November 29, 2022 Share Posted November 29, 2022 I'm using Delphi Rio 10.3 Professional But you can use Delphi Sydney 10.4 Community Quote Link to comment Share on other sites More sharing options...
lfgarrido Posted November 29, 2022 Share Posted November 29, 2022 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.