Skip to content

Instantly share code, notes, and snippets.

/// <summary>
/// The blogger repository implementation which works the same for Windows
/// and Windows Phone.
/// </summary>
public class BloggerRepository : IBloggerRepository
{
private UserCredential credential;
private BloggerService service;
private async Task AuthenticateAsync()
/// <summary>The blogs view model which contains all blog data.</summary>
public class BlogsViewModel : ViewModelBase
{
/// <summary>Gets the blog view models..</summary>
public ObservableCollection<BlogViewModel> Blogs { get; private set; }
private BlogViewModel selectedBlog;
/// <summary>Gets or sets the selected blog.</summary>
public BlogViewModel SelectedBlog
/// <summary>
/// Continues the app after retrieving the authorization code.
///
/// First it stores the authorization code result in the data store.
/// Then it calls the view model get blogs method, in order to retrieve all blogs.
/// The view model is responsible to check for if the authorization code exists in
/// the data store, and then, continue with the regular flow.
/// After retrieving all blogs, this method deletes the authorization code so it
/// won't be used in a next run.
/// </summary>
/// <summary>
/// On activated callback. It is used in order to continue the application
/// after the user authenticated.
/// </summary>
protected override void OnActivated(IActivatedEventArgs e)
{
base.OnActivated(e);
ContinuationManager = new Blogger.Common.ContinuationManager();
var continuationEventArgs = e as IContinuationActivatedEventArgs;
/// <summary>
/// ContinuationManager is used to detect if the most recent activation was due to a
/// authentication continuation.
///
/// Note: To keep this sample as simple as possible, the content of the file was changed
/// to support WebAuthenticationBrokerContinuation ONLY. Take a look in
/// http://msdn.microsoft.com/en-us/library/dn631755.aspx for a full documentation on how
/// to support continuation in other cases.
/// </summary>
public class ContinuationManager
UserCredential credential;
using (var stream = new FileStream("client_secrets.json",
FileMode.Open,
FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { BooksService.Scope.Books },
"user", CancellationToken.None);
}