-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathBaseProvider.cs
More file actions
68 lines (59 loc) · 1.99 KB
/
BaseProvider.cs
File metadata and controls
68 lines (59 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Net.Http;
using System.Threading.Tasks;
using CommunityToolkit.Net.Authentication.Extensions;
namespace CommunityToolkit.Net.Authentication
{
/// <summary>
/// A base construct for building Graph Providers on top of.
/// </summary>
public abstract class BaseProvider : IProvider
{
private ProviderState _state;
/// <summary>
/// Gets or sets the current state of the provider.
/// </summary>
public ProviderState State
{
get => _state;
protected set
{
var oldState = _state;
var newState = value;
if (oldState != newState)
{
_state = newState;
StateChanged?.Invoke(this, new ProviderStateChangedEventArgs(oldState, newState));
}
}
}
/// <inheritdoc/>
public event EventHandler<ProviderStateChangedEventArgs> StateChanged;
/// <summary>
/// Initializes a new instance of the <see cref="BaseProvider"/> class.
/// </summary>
public BaseProvider()
{
_state = ProviderState.Loading;
}
/// <inheritdoc />
public abstract Task LoginAsync();
/// <inheritdoc />
public abstract Task LogoutAsync();
/// <inheritdoc />
public abstract Task AuthenticateRequestAsync(HttpRequestMessage request);
/// <summary>
/// Append the Sdk version to the request headers.
/// </summary>
/// <param name="request">
/// The request to append the header to.
/// </param>
protected void AddSdkVersion(HttpRequestMessage request)
{
request.AddSdkVersion();
}
}
}