private static IInternalClient GetApi(CommandLineConfig config) { if (config.MomentumApiBaseUri == null) { throw new System.Exception("You must specify a MomentumApiBaseUri"); } var tokenProviderOptions = new LogicTokenProviderOptions { AuthorizationScope = config.TokenProvider.AuthorizationScope, ClientId = config.TokenProvider.ClientId, ClientSecret = config.TokenProvider.ClientSecret, AuthorizationTokenIssuer = config.TokenProvider.AuthorizationTokenIssuer, }; if (config.TokenProvider.AuthorizationTokenIssuer != null) { tokenProviderOptions.AuthorizationTokenIssuer = config.TokenProvider.AuthorizationTokenIssuer; } var httpClient = new HttpClient(); var tokenProviderFactory = new LogicTokenProviderFactory(tokenProviderOptions); var tokenProvider = tokenProviderFactory.GetProvider(httpClient); var client = new InternalClient(new TokenCredentials(tokenProvider)) { BaseUri = config.MomentumApiBaseUri, }; Log.Information("Created API with Base URI {BaseUri}", client.BaseUri); return(client); }
private static async Task Run(AppConfiguration configuration) { var validator = new ConfigurationValidator(configuration); if (!validator.Validate()) { return; } using (var httpClient = new HttpClient()) { LogicTokenProviderOptions tokenProviderOptions = new LogicTokenProviderOptions() { AuthorizationScope = configuration.TokenProvider.AuthorizationScope, // "https://logicidentityprod.onmicrosoft.com/ac1d197a-0e7c-4add-83c5-e1b30a08efd6/.default", AuthorizationTokenIssuer = new Uri(configuration.TokenProvider.AuthorizationTokenIssuer.ToString()), //new Uri("https://login.microsoftonline.com/logicidentityprod.onmicrosoft.com/oauth2/v2.0/token"), ClientId = configuration.TokenProvider.ClientId, //"085d3847-1b71-4203-aa52-bbb98d5ce57c", ClientSecret = configuration.TokenProvider.ClientSecret // "Ox30ERiezE+gbat7k9jtCmnfKGISFoA8AVjnJo8IgH8=" }; configuration.Citizen.SubscriptionId = configuration.SubscriptionId; configuration.Citizen.Serviceuri = configuration.Serviceuri; var tokenProviderFactory = new LogicTokenProviderFactory(tokenProviderOptions); var citizenDocumentClient = new CitizenDocumentsClient(httpClient, tokenProviderFactory, configuration.Citizen); var uploadDocument = await citizenDocumentClient.UploadAttachmentWithHttpMessagesAsync(configuration.ConfiguartionId, configuration.RetentionPeriodInDays, configuration.Cpr, configuration.DocumentType, configuration.Document, configuration.DocumentName).ConfigureAwait(false); if (uploadDocument == null) { Log.Error("There is error occured in upload"); return; } Log.Information($"Document uploaded successfully and details are :- DocumentId : {uploadDocument.DocumentId} ; DocumentType : {uploadDocument.DocumentType} ; FileAccessPageUrl : {uploadDocument.FileAccessPageUrl} "); var sendDocument = await citizenDocumentClient.SendDocumentWithHttpMessagesAsync(new SendCitizenDocumentRequest { ConfigurationId = new Guid(configuration.ConfiguartionId), SendingSystem = configuration.SendingSystem, Cpr = configuration.Cpr, DocumentType = configuration.SendDocumentType, CitizenDocumentId = uploadDocument.DocumentId, Title = configuration.title, DigitalPostCoverLetterId = uploadDocument.DocumentId, SnailMailCoverLetterId = uploadDocument.DocumentId }); if (sendDocument == null) { Log.Error("There is error occured in send document"); return; } Log.Information("Document was sent and got doc2mail messageId {MessageId}", sendDocument.MessageId); } }
private static async Task <string> Run(AppConfiguration configuration) { var validator = new ConfigurationValidator(configuration); if (!validator.Validate()) { return("The validation of provider configuration details failed"); } var tokenProviderOptions = new LogicTokenProviderOptions { AuthorizationScope = configuration.TokenProvider.AuthorizationScope, ClientId = configuration.TokenProvider.ClientId, ClientSecret = configuration.TokenProvider.ClientSecret, }; if (configuration.TokenProvider.AuthorizationTokenIssuer != null) { tokenProviderOptions.AuthorizationTokenIssuer = configuration.TokenProvider.AuthorizationTokenIssuer; } using (var httpClient = new HttpClient()) using (var tokenProviderFactory = new LogicTokenProviderFactory(tokenProviderOptions)) { configuration.Citizen.SubscriptionId = configuration.SubscriptionId; configuration.Citizen.Serviceuri = configuration.Serviceuri; var citizenDocumentClient = new CitizenDocumentsClient(httpClient, tokenProviderFactory, configuration.Citizen); var uploadDocument = await citizenDocumentClient.UploadAttachmentWithHttpMessagesAsync(configuration.ConfigurationId, configuration.RetentionPeriodInDays, configuration.Cpr, configuration.DocumentType, configuration.Document, configuration.DocumentName).ConfigureAwait(false); Log.Information("The {DocumentType} document with id {DocumentId} and file access page url {FileAccessPageUrl} is uploaded successfully", uploadDocument.DocumentType, uploadDocument.DocumentId, uploadDocument.FileAccessPageUrl); var sendDocument = await citizenDocumentClient.SendDocumentWithHttpMessagesAsync(new SendCitizenDocumentRequest { ConfigurationId = new Guid(configuration.ConfigurationId), SendingSystem = configuration.SendingSystem, Cpr = configuration.Cpr, DocumentType = configuration.SendDocumentType, CitizenDocumentId = uploadDocument.DocumentId, Title = configuration.Title, DigitalPostCoverLetterId = uploadDocument.DocumentId, SnailMailCoverLetterId = uploadDocument.DocumentId, }).ConfigureAwait(false); Log.Information("The document is sent successfully and doc2mail provider response message id is {MessageId}", sendDocument.MessageId); return("The citizen document was uploaded and sent successfully"); } }
private static async Task Run(AppSettings configuration) { var validator = new ConfigurationValidator(configuration); if (!validator.Validate()) { return; } var options = new LogicTokenProviderOptions { ClientId = configuration.ClientId, ClientSecret = configuration.ClientSecret, Tenant = configuration.Tenant, }; if (!string.IsNullOrEmpty(configuration.AuthorizationScope)) { options.AuthorizationScope = configuration.AuthorizationScope; } if (configuration.AuthorizationTokenIssuer != null) { options.AuthorizationTokenIssuer = configuration.AuthorizationTokenIssuer; } using (var tokenFactory = new LogicTokenProviderFactory(options)) using (var httpClient = new HttpClient()) { var provider = tokenFactory.GetProvider(httpClient); Log.Information("Requesting access to scope {Scope} with client id {ClientId}", options.AuthorizationScope, options.ClientId); var authHeader = await provider.GetAuthenticationHeaderAsync(CancellationToken.None).ConfigureAwait(false); Log.Information("Retrieved authorization header {Scheme} {Parameter}", authHeader.Scheme, authHeader.Parameter); var jwt = new JsonWebToken(authHeader.Parameter); Log.Information("Deserialized JWT {@Jwt}", jwt); } }
private static async Task <string> Run(AppConfiguration configuration) { var validator = new ConfigurationValidator(configuration); if (!validator.Validate()) { return("The validation of provider configuration details failed"); } var tokenProviderOptions = new LogicTokenProviderOptions { AuthorizationScope = configuration.TokenProvider.AuthorizationScope, ClientId = configuration.TokenProvider.ClientId, ClientSecret = configuration.TokenProvider.ClientSecret, }; if (configuration.TokenProvider.AuthorizationTokenIssuer != null) { tokenProviderOptions.AuthorizationTokenIssuer = configuration.TokenProvider.AuthorizationTokenIssuer; } using var httpClient = new HttpClient(); using var tokenProviderFactory = new LogicTokenProviderFactory(tokenProviderOptions); var options = new CitizenDocumentsOptions(configuration.SubscriptionId, configuration.ServiceUri); using var citizenDocumentClient = new CitizenDocumentsClient(httpClient, tokenProviderFactory, options); using Stream stream = File.OpenRead(configuration.DocumentName); var uploadWithLargeSizeDocument = await citizenDocumentClient.UploadFileAsync(stream, new UploadFileParameters( new Guid(configuration.ConfigurationId), new Guid(configuration.SubscriptionId), cpr : configuration.Cpr, documentName : configuration.DocumentName, documentType : configuration.DocumentType, retentionPeriodInDays : configuration.RetentionPeriodInDays)) .ConfigureAwait(false); Log.Information("The {DocumentType} document with id {DocumentId} and file access page url {FileAccessPageUrl} is uploaded successfully", uploadWithLargeSizeDocument.DocumentType, uploadWithLargeSizeDocument.DocumentId, uploadWithLargeSizeDocument.FileAccessPageUrl); return("The citizen document was uploaded successfully"); }