Skip to content

Commit

Permalink
Module: Identity (MSAL.NET) (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfevia authored Sep 21, 2024
1 parent c887f32 commit a1e34a9
Show file tree
Hide file tree
Showing 9 changed files with 498 additions and 0 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Identity.Client" Version="4.61.3" />
<PackageVersion Include="Microsoft.PowerFx.Interpreter" Version="1.2.0" />
<PackageVersion Include="Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK" Version="1.4.233.23144-rc" />
<PackageVersion Include="Microsoft.Windows.SDK.Contracts" Version="10.0.26100.1" />
Expand Down
7 changes: 7 additions & 0 deletions PowerAutomate.Desktop.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modules.Conditionals.Action
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modules.PowerFx.Actions", "modules\Modules.PowerFx.Actions\Modules.PowerFx.Actions.csproj", "{86C08ED2-7025-4898-BE9B-BCD10A0C5774}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Modules.Identity.Actions", "modules\Modules.Identity.Actions\Modules.Identity.Actions.csproj", "{7D933F4B-9793-4B10-B63D-4247F7E70FF2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -139,6 +141,10 @@ Global
{86C08ED2-7025-4898-BE9B-BCD10A0C5774}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86C08ED2-7025-4898-BE9B-BCD10A0C5774}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86C08ED2-7025-4898-BE9B-BCD10A0C5774}.Release|Any CPU.Build.0 = Release|Any CPU
{7D933F4B-9793-4B10-B63D-4247F7E70FF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D933F4B-9793-4B10-B63D-4247F7E70FF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D933F4B-9793-4B10-B63D-4247F7E70FF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D933F4B-9793-4B10-B63D-4247F7E70FF2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -173,6 +179,7 @@ Global
{22D1EE4E-815F-48F2-AB46-754518B1F914} = {FEFFE5BC-DCBD-466C-87DE-5B9D8A553256}
{791698E0-931E-4F35-97A4-B050FD0B4F82} = {22D1EE4E-815F-48F2-AB46-754518B1F914}
{86C08ED2-7025-4898-BE9B-BCD10A0C5774} = {3B78C634-DFD6-43DA-A30E-33AC42224BD4}
{7D933F4B-9793-4B10-B63D-4247F7E70FF2} = {3B78C634-DFD6-43DA-A30E-33AC42224BD4}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Modules.Actions.Shared\Modules.Actions.Shared.projitems*{7e19e2f1-6de7-4a0e-aed8-7cea38b166af}*SharedItemsImports = 13
Expand Down
1 change: 1 addition & 0 deletions PowerAutomate.Desktop.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ Storyboard.*, From, To, Duration</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002EMemberReordering_002EMigrations_002ECSharpFileLayoutPatternRemoveIsAttributeUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/XamlPreview/WpfPreviewEnabled/@EntryValue">False</s:Boolean>
Expand Down
10 changes: 10 additions & 0 deletions modules/Modules.Identity.Actions/ErrorCodes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// ---------------------------------------------------
// Copyright (c) Jesus Fernandez. All Rights Reserved.
// ---------------------------------------------------

namespace PowerAutomate.Desktop.Modules.Identity.Actions;

internal static class ErrorCodes
{
public const string Unknown = "UnknownError";
}
56 changes: 56 additions & 0 deletions modules/Modules.Identity.Actions/GetAccessTokenAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// ---------------------------------------------------
// Copyright (c) Jesus Fernandez. All Rights Reserved.
// ---------------------------------------------------

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Identity.Client;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes;

namespace PowerAutomate.Desktop.Modules.Identity.Actions;

[Action(Id = "GetAccessToken")]
[Throws(ErrorCodes.Unknown)]
[SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global", Justification = "PowerAutomate.Desktop.Module.Action")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "PowerAutomate.Desktop.Module.Action")]
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global", Justification = "PowerAutomate.Desktop.Module.Action")]
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global", Justification = "PowerAutomate.Desktop.Module.Action")]
[SuppressMessage("ReSharper", "UnusedType.Global", Justification = "PowerAutomate.Desktop.Module.Action")]
public class GetAccessTokenAction : ActionBase
{
[InputArgument(Order = 3, Required = true)]
public string Authority { get; set; } = null!;

[InputArgument(Order = 1, Required = true)]
public string ClientId { get; set; } = null!;

[InputArgument(Order = 2, Required = true)]
public string ClientSecret { get; set; } = null!;

[InputArgument(Order = 4, Required = true)]
public List<string> Scopes { get; set; } = null!;

[OutputArgument(Order = 1)]
public string Token { get; set; } = null!;

public override void Execute(ActionContext context)
{
try
{
var app = ConfidentialClientApplicationBuilder.Create(ClientId)
.WithClientSecret(ClientSecret)
.WithAuthority(new Uri(Authority))
.Build();

var clientParameterBuilder = app.AcquireTokenForClient(Scopes);
var authenticationResult = clientParameterBuilder.ExecuteAsync().GetAwaiter().GetResult();
Token = authenticationResult.AccessToken;
}
catch (Exception ex)
{
throw new ActionException(ErrorCodes.Unknown, ex.Message, ex);
}
}
}
31 changes: 31 additions & 0 deletions modules/Modules.Identity.Actions/Modules.Identity.Actions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyTitle>Identity</AssemblyTitle>
<TargetFramework>net472</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<PackCustomModule Condition=" '$(Configuration)' == 'Debug' ">true</PackCustomModule>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Identity.Client" />
<PackageReference Include="Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
215 changes: 215 additions & 0 deletions modules/Modules.Identity.Actions/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a1e34a9

Please sign in to comment.