AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Indy und OAuth / Microsoft365
Thema durchsuchen
Ansicht
Themen-Optionen

Indy und OAuth / Microsoft365

Ein Thema von friedt99 · begonnen am 5. Sep 2023 · letzter Beitrag vom 2. Jul 2025
 
Thomasl

Registriert seit: 19. Jun 2006
Ort: Vreden
71 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: Indy und OAuth / Microsoft365

  Alt 6. Sep 2023, 09:24
ist die TIdSASLXOAuth2 in Indy10\Protocols mitlerweile schon enthalten?

diese geht
Delphi-Quellcode:
unit IdSASLXOAUTH;

interface

uses
  Classes,
  IdSASL
  ;

type
  TIdSASLXOAuth = class(TIdSASL)
  private
    FToken: string;
    FUser: string;
    FTwoLinePopFormat: Boolean;
  public
    property Token: string read FToken write FToken;
    property User: string read FUser write FUser;
    property TwoLinePopFormat: Boolean read FTwoLinePopFormat write FTwoLinePopFormat;
    class function ServiceName: TIdSASLServiceName; override;
    constructor Create(AOwner: TComponent);
    destructor Destroy; override;
    function TryStartAuthenticate(const AHost, AProtocolName : String; var VInitialResponse: String): Boolean; override;
    function ContinueAuthenticate(const ALastResponse, AHost, AProtocolName : string): string; override;
    function StartAuthenticate(const AChallenge, AHost, AProtocolName: string): string; override;
    { For cleaning up after Authentication }
    procedure FinishAuthenticate; override;
  end;

implementation

{ TIdSASLXOAuth }

class function TIdSASLXOAuth.ServiceName: TIdSASLServiceName;
begin
  Result := 'XOAUTH2';
end;

constructor TIdSASLXOAuth.Create(AOwner: TComponent);
begin
  inherited;
end;

destructor TIdSASLXOAuth.Destroy;
begin
  inherited;
end;

function TIdSASLXOAuth.TryStartAuthenticate(const AHost, AProtocolName: String; var VInitialResponse: String): Boolean;
begin
  if (AProtocolName = 'pop') and FTwoLinePopFormat then
  begin
    // Don't send anything yet
  end
  else
  begin
    VInitialResponse := 'user=' + FUser + Chr($01) + 'auth=Bearer ' + FToken + Chr($01) + Chr($01);
  end;
  Result := True;
end;

function TIdSASLXOAuth.StartAuthenticate(const AChallenge, AHost, AProtocolName: string): string;
begin
  Result := 'user=' + FUser + Chr($01) + 'auth=Bearer ' + FToken + Chr($01) + Chr($01);
end;

function TIdSASLXOAuth.ContinueAuthenticate(const ALastResponse, AHost, AProtocolName: string): string;
begin
  // Nothing to do
end;

procedure TIdSASLXOAuth.FinishAuthenticate;
begin
  // Nothing to do
end;

end.

Delphi-Quellcode:
          IdSASLXOAUTH := TIdSASLXOAuth.Create(SMTP);
          IdSASLXOAUTH.Token := FToken; // ca. 2300 Zeichen lang bei Microsoft
          IdSASLXOAUTH.User := FBenutzername;
          IdSASLXOAUTH.TwoLinePopFormat := true;
          SMTP.SASLMechanisms.Add.SASL := IdSASLXOAUTH;
Thomas Levering
  Mit Zitat antworten Zitat
 

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz