本文整理汇总了C#中OAuth2Authenticator.LoadAccessToken方法的典型用法代码示例。如果您正苦于以下问题:C# OAuth2Authenticator.LoadAccessToken方法的具体用法?C# OAuth2Authenticator.LoadAccessToken怎么用?C# OAuth2Authenticator.LoadAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuth2Authenticator
的用法示例。
在下文中一共展示了OAuth2Authenticator.LoadAccessToken方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckForValidAccessTokenTest
public void CheckForValidAccessTokenTest()
{
int accessTokenCounter = 1;
var state = new AuthorizationState();
var client = new NativeApplicationClient(new Uri("http://example.com"));
var auth = new OAuth2Authenticator<NativeApplicationClient>(
client, (clt) =>
{
// Load a "cached" access token.
state.AccessToken = "token" + (accessTokenCounter++);
return state;
});
// Check that the initial state is null.
Assert.IsNull(auth.State);
// Check that the state was set when .LoadAccessToken() is called.
auth.LoadAccessToken();
Assert.AreEqual(state, auth.State);
Assert.AreEqual("token1", auth.State.AccessToken);
// Check that it wont be set again.
auth.LoadAccessToken();
Assert.AreEqual("token1", auth.State.AccessToken);
// Check that it is set if our state gets invalid.
state.AccessToken = null;
auth.LoadAccessToken();
Assert.AreEqual("token2", auth.State.AccessToken);
}
示例2: GetAuthenticatorFromState
/// <summary>
/// Retrieve an IAuthenticator instance using the provided state.
/// </summary>
/// <param name="credentials">OAuth 2.0 credentials to use.</param>
/// <returns>Authenticator using the provided OAuth 2.0 credentials</returns>
public static IAuthenticator GetAuthenticatorFromState(IAuthorizationState credentials)
{
var provider = new StoredStateClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET, credentials);
var auth = new OAuth2Authenticator<StoredStateClient>(provider, StoredStateClient.GetState);
auth.LoadAccessToken();
return auth;
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = "783795063122.apps.googleusercontent.com";
provider.ClientSecret = "_OQKo8_narny3sSrFcgCBWQV";
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);
auth.LoadAccessToken();
}
示例4: DelegateTest
public void DelegateTest()
{
var state = new AuthorizationState() { AccessToken = "Test" };
var client = new NativeApplicationClient(new Uri("http://example.com"));
var auth = new OAuth2Authenticator<NativeApplicationClient>(client, (clt) => state);
// Check that the state was set.
auth.LoadAccessToken();
Assert.AreEqual(state, auth.State);
}
示例5: GetAuthenticator
public static GoogleAuthenticator GetAuthenticator(string authorizationCode)
{
var client = new NativeApplicationClient(GoogleAuthenticationServer.Description, _clientId, _clientSecret);
IAuthorizationState state = new AuthorizationState() { Callback = new Uri(_redirectUri) };
state = client.ProcessUserAuthorization(authorizationCode, state);
var auth = new OAuth2Authenticator<NativeApplicationClient>(client, (c) => state);
auth.LoadAccessToken();
return new GoogleAuthenticator(auth);
}
示例6: RefreshAuthenticator
public static GoogleAuthenticator RefreshAuthenticator(string refreshToken)
{
var state = new AuthorizationState(_scopes)
{
RefreshToken = refreshToken
};
var client = new NativeApplicationClient(GoogleAuthenticationServer.Description, _clientId, _clientSecret);
bool result = client.RefreshToken(state);
var auth = new OAuth2Authenticator<NativeApplicationClient>(client, (c) => state);
auth.LoadAccessToken();
return new GoogleAuthenticator(auth);
}
示例7: SaveRefreshToken
/// <summary>
/// Returng Google Analytics Refresh token
/// </summary>
/// <param name="code">The code obtained in callback action</param>
public static void SaveRefreshToken(string code)
{
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = Settings.ClientIdentifier;
provider.ClientSecret = Settings.ClientSecret;
var request = HttpContext.Current.Request;
var authenticator = new OAuth2Authenticator<NativeApplicationClient>(provider, (arg) =>
{
IAuthorizationState state = new AuthorizationState(new[] { "https://www.googleapis.com/auth/analytics.readonly" });
state.Callback = new Uri(string.Format("{0}://{1}{2}/GoogleAnalytics/Callback", request.Url.Scheme, request.Url.Host, request.Url.Port == 80 ? string.Empty : ":" + request.Url.Port));
var result = arg.ProcessUserAuthorization(code, state);
if (result.RefreshToken == null)
{
throw new Exception("Can't get refresh token. Invalid credentials.");
}
Settings.RefreshToken = result.RefreshToken;
return result;
});
authenticator.LoadAccessToken();
}
示例8: Main
static void Main(string[] args)
{
LoadStorageKey();
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = "783795063122.apps.googleusercontent.com";
provider.ClientSecret = "_OQKo8_narny3sSrFcgCBWQV";
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);
auth.LoadAccessToken();
Console.ReadKey();
}
示例9: GetAuthenticator
/// <summary>
/// Retrieve an IAuthenticator instance using the provided state.
/// </summary>
/// <returns>Authenticator using the provided OAuth 2.0 credentials</returns>
public static IAuthenticator GetAuthenticator(string refreshToken, string accessKey)
{
var credentials = new AuthorizationState(null)
{
RefreshToken = refreshToken,
AccessToken = accessKey
};
var provider = new StoredStateClient(GoogleAuthenticationServer.Description, "647667148.apps.googleusercontent.com", "SHvBqFmGtXq5bTPqY242oNvB", credentials);
var auth = new OAuth2Authenticator<StoredStateClient>(provider, StoredStateClient.GetState);
auth.LoadAccessToken();
return auth;
}
示例10: GetCalenders
public CalendarListResource.GetRequest GetCalenders()
{
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = "36225438087.apps.googleusercontent.com";
provider.ClientSecret = "t437LrazWglB2v_OeAqMaj-r";
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
// Create the service. This will automatically call the previously registered authenticator.
auth.LoadAccessToken();
var service = new CalendarService(auth);
//auth code
// 4/USRsNMQpLCUgsr2cv1VZM0U-cx5t.ohfarZngF4kVOl05ti8ZT3YdL5qWcwI
var calendar = service.CalendarList.Get("[email protected]");
var oAuth = calendar.Oauth_token;
return calendar;
}