This file contains hidden or 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
| 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); |
This file contains hidden or 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
| var count = await graphServiceClient | |
| .Users | |
| .Count //Where applicable to enable the use of $count | |
| .GetAsync(requestConfiguration => | |
| requestConfiguration.Headers.Add("ConsistencyLevel","eventual")); |
This file contains hidden or 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
| //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 |
This file contains hidden or 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
| //var message = .... | |
| //var saveToSentItems = ... | |
| var body = new SendMailPostRequestBody | |
| { | |
| Message = message, | |
| SaveToSentItems = saveToSentItems | |
| }; | |
| await graphServiceClient.Me | |
| .SendMail //method SendMail |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| messages, err := client.Me().MailFolders().ByMailFolderId("Inbox").Messages().Get(context.Background(), nil) |
This file contains hidden or 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
| 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" | |
| ) |
This file contains hidden or 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
| 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" |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 | |
| }, | |
| }) |