page_type: sample description: This sample demonstrates how to use the Microsoft Graph connector API to create a custom connector that indexes issues and repositories from GitHub. products:
Microsoft Graph connectors let you add your own data to the semantic search index and have it power various Microsoft 365 experiences. This .NET application shows you how to use the Microsoft Graph connector API to create a custom connector that indexes issues and repositories from GitHub. This connector sample powers experiences such as Microsoft Search, Copilot in Teams, the Microsoft 365 App, and more.
The Microsoft Graph connector experiences that will be enabled in the sample include:
If you want to enable the simplified admin experience in the Teams admin center, you will also need the following.
Go to the Azure Active Directory admin center and sign in with an administrator account.
In the left pane, select Azure Active Directory, and under Manage, select App registrations.
Select New registration.
Complete the Register an application form with the following values, and then select Register.
GitHub Connector
On the GitHub Connector overview page, copy the values of Application (client) ID and Directory (tenant) ID. You will need both in the following section.
Select API Permissions under Manage.
Remove the default User.Read permission under Configured permissions by selecting the ellipses (...) in its row and selecting Remove permission.
Select Add a permission, and then select Microsoft Graph.
Select Application permissions, and add the following permissions:
Select Grant admin consent for..., and then select Yes when prompted.
Select Certificates & secrets under Manage, and then select New client secret.
Enter a description and choose an expiration time for the secret, and then select Add.
Copy and save the new secret. You will need it in the following section.
[!IMPORTANT] This client secret is never shown again, so make sure you copy it now.
Login to your GitHub account and access your profile page.
Select Developer settings.
Select Personal access tokens, choose Fine-grained tokens, then select Generate new token.
Complete the New fine-grained personal access token form with the following values, then select Generate Token
Copy and save the newly generated token. You will need it in the following section.
Open appsettings.json and update the following values. Alternatively, make a copy of appsettings.json named appsettings.Development.json and change the values there.
Setting | Value |
---|---|
clientId |
The Application (client) ID of your app registration in the Azure portal. |
tenantId |
The Directory (tenant) ID of your app registration in the Azure portal. |
gitHubRepoOwner |
The GitHub user or organization to read data from. |
gitHubRepo |
The GitHub repository to ingest issues from. Must be owned by the user or organization set in gitHubRepoOwner . |
portNumber |
The port number to listen on when using the simplified admin experience in the Teams admin center |
placeholderUserId |
A user ID in your Microsoft 365 tenant. You can get the user ID of a user in the Azure portal. Select an Azure Active Directory user and copy the value of their Object ID. |
Open your command line interface (CLI) in the directory where GitHubConnector.csproj is located.
Run the following commands to store the client secret and GitHub token in the user secret store.
dotnet user-secrets set settings:clientSecret "YOUR_CLIENT_SECRET_FROM_APP_REGISTRATION"
dotnet user-secrets set settings:githubToken "YOUR_GITHUB_PERSONAL_ACCESS_TOKEN"
This sample offers two ways of creating a connection. You can create one interactively, selecting steps from the sample's command line menu, or you can create a connector using the simplified admin experience in the Teams admin center.
[!NOTE] You do not have to do use both of these methods - once a connection is created, you can continue to the Ingest items section.
In this step, you will build and run the sample as an interactive console app. This code sample will create a new connection, register the schema, and then push GitHub repo or issues into that connection.
dotnet build
to build the sample.dotnet run
to run the sample.The connection is now ready to ingest items.
There are additional configuration steps to run the sample in simplified admin mode.
The simplified admin experience in the Teams admin center communicates with the sample connector by sending an HTTP POST request. In this section you will create a dev tunnel to allow the Teams admin center to send the POST to the sample running on your local development machine.
If you do not have the devtunnel CLI installed, follow these instructions to install.
Run the following command to login to the dev tunnel service. You can login with either a Microsoft Azure Active Directory account, a Microsoft account, or a GitHub account.
devtunnel user login
Run the following commands to create a tunnel. Copy the Tunnel ID from the output.
devtunnel create --allow-anonymous
Run the following command to assign a port to the tunnel. Replace tunnel-id
with the Tunnel ID copied in the previous step, and port-number
with the HTTP port set in your appsettings.json.
devtunnel port create tunnel-id -p port-number
Run the following command to host the tunnel. Replace tunnel-id
with the Tunnel ID copied in the previous step.
devtunnel host tunnel-id
Copy the URL labeled Connect via browser.
[!NOTE] The output shows two URLs for Connect via browser. Be sure to copy only one of them.
YOUR_CLIENT_ID_HERE
with the Application (client) ID of your app registration in the Azure portal.YOUR_DEV_TUNNEL_URL_HERE
with your dev tunnel URL.dotnet build
to build the sample.dotnet run -- --use-simplified-admin
to run the sample.The connection is now ready to ingest items.
[!IMPORTANT] Connectors created via the simplified admin experience are configured to ingest GitHub issues. Attempting to ingest repositories with this connector will result in an error.
dotnet run
to run the sample in interactive mode.In this step, you will create search verticals and result types to customize the search results in Microsoft SharePoint, Microsoft Office, and Microsoft Search in Bing.
[!NOTE] It may take a few hours before your new vertical shows up in Microsoft Search.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.