Skip to content

Instantly share code, notes, and snippets.

View maisarissi's full-sized avatar

Maísa Rissi maisarissi

  • São Paulo, Brazil
  • 02:36 (UTC -03:00)
View GitHub Profile
@maisarissi
maisarissi / CustomAuthFlow.cs
Last active February 8, 2023 20:28
msgraph-dotnet-v5-rc-custom-auth-flow
public class TokenProvider : IAccessTokenProvider
{
public Task<string> GetAuthorizationTokenAsync(Uri uri,
Dictionary<string,
object> additionalAuthenticationContext = default,
CancellationToken cancellationToken = default)
{
var token = "token";
//get the token and return it in your own way
return Task.FromResult(token);
@maisarissi
maisarissi / Count.cs
Created February 8, 2023 20:27
msgraph-dotnet-v5-rc-count
var count = await graphServiceClient
    .Users
    .Count //Where applicable to enable the use of $count
    .GetAsync(requestConfiguration =>
        requestConfiguration.Headers.Add("ConsistencyLevel","eventual"));
@maisarissi
maisarissi / ODataCastSimplified.cs
Last active December 7, 2023 19:42
msgraph-dotnet-v5-ga-odata-cast
//Fetching the members of a group who are of the type User
var usersInGroup = await graphServiceClient
    .Groups["group-id"]
    .Members
    .GraphUser //cast to User
    .GetAsync();
List<User> userList = usersInGroup.Value;
//Similarly, members of the group of type ServicePrincipal
@maisarissi
maisarissi / MethodNameSimplified.cs
Last active March 2, 2023 17:52
msgraph-dotnet-v5-method-parameter-object
//var message = ....
//var saveToSentItems = ...
var body = new SendMailPostRequestBody
{
    Message = message,
    SaveToSentItems = saveToSentItems
};
await graphServiceClient.Me
    .SendMail //method SendMail
@maisarissi
maisarissi / send_mail.go
Created May 2, 2023 20:19
microsoftgraph-go-v1-send-mail
func (g *GraphHelper) SendMail() error {
message := models.NewMessage()
subject := "Meet for lunch?"
content := "The new cafeteria is open."
body := models.NewItemBody()
message.SetSubject(&subject)
message.SetBody(body)
contentType := models.TEXT_BODYTYPE
body.SetContentType(&contentType)
@maisarissi
maisarissi / messages_inbox.go
Created May 2, 2023 20:21
microsoftgraph-go-v1-messages-inbox
messages, err := client.Me().MailFolders().ByMailFolderId("Inbox").Messages().Get(context.Background(), nil)
@maisarissi
maisarissi / v1_and_beta_clients.go
Created May 2, 2023 20:26
microsoftgraph-go-v1-both_clients
import (
    "context"
    "fmt"
    "log"
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    auth "github.com/microsoft/kiota-authentication-azure-go"
    msgraphbeta "github.com/microsoftgraph/msgraph-beta-sdk-go"
    msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
)
@maisarissi
maisarissi / devicecodeflow.go
Created May 2, 2023 20:30
microsoftgraph-go-v1-devicecodeflow
import (
    "context"
    "fmt"
    "log"
    "os"
    "strings"
    "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    auth "github.com/microsoft/kiota-authentication-azure-go"
    msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
@maisarissi
maisarissi / pagination.go
Created May 2, 2023 20:32
microsoftgraph-go-v1-pagination
result, _ := g.userClient.Me().Messages().Get(context.Background(), &requestConfiguration)
    // Initialize iterator
    pageIterator, _ := msgraphcore.NewPageIterator[models.Message](result, g.userClient.GetAdapter(), models.CreateMessageCollectionResponseFromDiscriminatorValue)
    // Any custom headers sent in original request should also be added
    // to the iterator
    pageIterator.SetHeaders(headers)
    // Iterate over all pages
@maisarissi
maisarissi / get_me.go
Last active May 4, 2023 19:56
microsoftgraph-go-v1-get-me
scopes := []string{"Mail.Read", "Mail.Send", "User.Read"}
// Create the device code credential
credential, _ := azidentity.NewDeviceCodeCredential(&azidentity.DeviceCodeCredentialOptions{
ClientID: "app_id",
TenantID: "tenant_id",
UserPrompt: func(ctx context.Context, message azidentity.DeviceCodeMessage) error {
fmt.Println(message.Message)
return nil
},
})