Ejemplo n.º 1
0
        // Get an access token for the given context and resourceId. An attempt is first made to
        // acquire the token silently. If that fails, then we try to acquire the token by prompting the user.
        public static async Task <GraphServiceClient> GetAuthenticatedClientAsync()
        {
            if (graphClient == null)
            {
                var authenticationProvider = new OAuth2AuthenticationProvider(
                    new AppConfig
                {
                    ClientId  = clientId,
                    ReturnUrl = returnUrl,
                    Scopes    = new string[]
                    {
                        "openid",
                        "offline_access",
                        "https://graph.microsoft.com/User.Read",
                        "https://graph.microsoft.com/Mail.Send",
                    },
                });

                await authenticationProvider.AuthenticateAsync();

                graphClient = new GraphServiceClient(authenticationProvider);
            }

            return(graphClient);
        }
Ejemplo n.º 2
0
        // Get a Graph client.
        public static async Task <GraphServiceClient> GetAuthenticatedClientAsync()
        {
            if (graphClient == null)
            {
                var authenticationProvider = new OAuth2AuthenticationProvider(
                    clientId,
                    returnUrl,
                    new string[]
                {
                    "offline_access",
                    "https://graph.microsoft.com/Mail.Read",
                });

                await authenticationProvider.AuthenticateAsync();

                graphClient = new GraphServiceClient(authenticationProvider);
            }

            return(graphClient);
        }