Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions docs/Auth-Device-code-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
### **1. Register Your Application in Azure AD**

1. **Sign in to the Azure Portal**
Navigate to [Azure Portal](https://portal.azure.com).

2. **Register a New Application**
- Go to **Azure Active Directory** > **App registrations** > **New registration**.
- Enter the following details:
- **Name**: Enter a meaningful name for your app.
- **Supported Account Types**: Choose an option based on your needs:
- Single tenant: Accounts in your organization only.
- Multi-tenant: Accounts in any organization's directory.
- **Redirect URI**: This is not required for Device Code Flow but can be added later if needed.
- Click **Register**.

3. **Copy the Application (Client) ID**
- After registration, go to the **Overview** section.
- Copy the **Application (client) ID** and the **Directory (tenant) ID** and save it for later.

![image](/docs/Images/AppDetails.png)

4. **Configure API Permissions**
- Navigate to **API Permissions** > **Add a permission**.
- Select **Azure DevOps** or any other API you want to access.

![image](/docs/Images/ChooseAPI.png)

- Choose **Delegated permissions**

- Add the required scopes (e.g., `User.Read`).

5. **Following are the scopes required.**

| Scope | Description |
|---------------------------|------------------------------------------|
| vso.agentpools | Agent Pools (read) |
| vso.build_execute | Build (read and execute) |
| vso.code_full | Code (full) |
| vso.dashboards_manage | Team dashboards (manage) |
| vso.extension_manage | Extensions (read and manage) |
| vso.profile | User profile (read) |
| vso.project_manage | Project and team (read, write and manage)|
| vso.release_manage | Release (read, write, execute and manage)|
| vso.serviceendpoint_manage| Service Endpoints (read, query and manage)|
| vso.test_write | Test management (read and write) |
| vso.variablegroups_write | Variable Groups (read, create) |
| vso.work_full | Work items (full) |

---

### **2. Configure the App Settings**
1. Open your application’s configuration file (e.g., `appsettings.json`) under AppSettings.
2. Add the following details:
```json
{
"AppSettings": {
"...": "...",
"clientId": "<Your Application (Client) ID>",
"tenantId": "<Your Directory (Tenant) ID>",
"scope": "499b84ac-1321-427f-aa17-267ca6975798/.default"
}
}
```
Replace placeholders with the actual values from the Azure Portal.

---

### **3. Test the Application**
1. Run your application.
2. The app will display a message instructing the user to go to `https://microsoft.com/devicelogin` and enter the provided device code.
3. After entering the code, users will authenticate, and the app will receive an access token.

Binary file added docs/Images/AppDetails.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Images/ChooseAPI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Images/ChoosePermission.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/ADOGenerator/ADOGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@
<None Remove="Templates\DL-Octopus\WorkItems\Task.json" />
</ItemGroup>
<ItemGroup>

<PackageReference Include="Microsoft.Identity.Client" Version="4.66.2" />

<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />

<PackageReference Include="Microsoft.VisualStudio.Services.Client" Version="19.225.1" />
<PackageReference Include="Microsoft.VisualStudio.Services.ExtensionManagement.WebApi" Version="19.225.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
22 changes: 22 additions & 0 deletions src/ADOGenerator/IServices/IAuthService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.Identity.Client;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ADOGenerator.IServices
{
public interface IAuthService
{
public Task<AuthenticationResult> AcquireTokenAsync(IPublicClientApplication app);
public Task<string> GetProfileInfoAsync(string accessToken);

public Task<JObject> GetOrganizationsAsync(string accessToken, string memberId);

public Task<string> SelectOrganization(string accessToken, JObject accountsJson);

//public Task<string> GetProjectsAsync(string accessToken, string selectedAccountName);
}
}
21 changes: 21 additions & 0 deletions src/ADOGenerator/IServices/IInitService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using ADOGenerator.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ADOGenerator.IServices
{
public interface IInitService
{
string ExtractHref(string link);

string ReadSecret();

void PrintErrorMessage(string message);

bool CheckProjectName(string name);
}
}
2 changes: 1 addition & 1 deletion src/ADOGenerator/IServices/IProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IProjectService

string GetJsonFilePath(bool IsPrivate, string TemplateFolder, string TemplateName, string FileName = "");

string[] CreateProjectEnvironment(Project model);
bool CreateProjectEnvironment(Project model);
// string[] CreateProjectEnvironment(string organizationName, string newProjectName, string token, string templateUsed, string templateFolder);

public bool CheckForInstalledExtensions(string extensionJsonFile, string token, string account);
Expand Down
1 change: 1 addition & 0 deletions src/ADOGenerator/Models/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Project()
public string PrivateTemplatePath { get; set; }
public string templateImage { get; set; }
public string profileImage { get; set; }
public string adoAuthScheme { get; set; }
}
public class EnvironmentValues
{
Expand Down
Loading
Loading