当前位置: 首页>>代码示例>>C#>>正文


C# OAuth2Authenticator.LoadAccessToken方法代码示例

本文整理汇总了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);
        }
开发者ID:jithuin,项目名称:infogeezer,代码行数:30,代码来源:OAuth2AuthenticatorTest.cs

示例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;
 }
开发者ID:festigf,项目名称:g3,代码行数:12,代码来源:OAuth2Credential.cs

示例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();
 }
开发者ID:Fitmedia,项目名称:x.stat,代码行数:8,代码来源:ga_auth.aspx.cs

示例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);
        }
开发者ID:jithuin,项目名称:infogeezer,代码行数:10,代码来源:OAuth2AuthenticatorTest.cs

示例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);
        }
开发者ID:tophitter,项目名称:google-calendar-sample,代码行数:11,代码来源:GoogleAuthorizationHelper.cs

示例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);
        }
开发者ID:tophitter,项目名称:google-calendar-sample,代码行数:15,代码来源:GoogleAuthorizationHelper.cs

示例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();
 }
开发者ID:calebjenkins,项目名称:linq2ga,代码行数:24,代码来源:GoogleAnalyticsServiceManager.cs

示例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();
        }
开发者ID:Fitmedia,项目名称:x.stat,代码行数:11,代码来源:Program.cs

示例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;
        }
开发者ID:andrerpena,项目名称:Cerebello,代码行数:17,代码来源:GoogleApiHelper.cs

示例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;
        }
开发者ID:woodbase,项目名称:Woodbase.RefereeToolkit,代码行数:16,代码来源:Calendar.cs


注:本文中的OAuth2Authenticator.LoadAccessToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。