示例#1
0
        public async Task AuthenticateRequestAsync(HttpRequestMessage request)
        {
            authenticator = new OAuth2Authenticator(ServiceConstants.MSA_CLIENT_ID,
                                                    ServiceConstants.MSA_CLIENT_SECRET,
                                                    string.Join(",", ServiceConstants.Scopes),
                                                    new Uri(ServiceConstants.AUTHENTICATION_URL),
                                                    new Uri(ServiceConstants.RETURN_URL),
                                                    new Uri(ServiceConstants.TOKEN_URL));

            var protectedData = new ProtectedData();
            var accessToken   = string.Empty;
            var refreshToken  = protectedData.Unprotect(ServiceConstants.REFRESH_TOKEN);

            if (string.IsNullOrEmpty(refreshToken))
            {
                var authView = new OAuthView();
                var result   = await authView.ShowWebView();

                if (result != null)
                {
                    // pass access_token to the onedrive sdk
                    accessToken = result[ServiceConstants.ACCESS_TOKEN];

                    // add refresh token to the password vault to enable future silent login
                    new ProtectedData().Protect(ServiceConstants.REFRESH_TOKEN, result[ServiceConstants.REFRESH_TOKEN]);
                }
            }
            else
            {
                accessToken = await authenticator.RequestRefreshTokenAsync(refreshToken);
            }

            request.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
        }
示例#2
0
        private void ShowOAuth(object sender, RoutedEventArgs e)
        {
            var vm     = new OAuthViewModel(_environment);
            var view   = new OAuthView();
            var window = new DialogWindow(view)
            {
                DataContext = vm
            };

            window.ShowDialog();
        }