-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
498 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
modules/Modules.Identity.Actions/Modules.Identity.Actions.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
215
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.
Oops, something went wrong.
Oops, something went wrong.