コード例 #1
0
 public WebSession(string baseUrl, WebSession.AuthenticationMode securityMode, string userName, string password)
 {
     this.baseUrl  = baseUrl;
     this.userName = userName;
     this.password = password;
     authenticator = WebAuthenticatorFactory.Create(securityMode, baseUrl);
 }
コード例 #2
0
 static IPlatformWebAuthenticatorCallback AsPlatformCallback(this IWebAuthenticator webAuthenticator)
 {
     if (webAuthenticator is not IPlatformWebAuthenticatorCallback platform)
     {
         throw new PlatformNotSupportedException("This implementation of IWebAuthenticator does not implement IPlatformWebAuthenticatorCallback.");
     }
     return(platform);
 }
コード例 #3
0
        public static bool ContinueUserActivity(this IWebAuthenticator webAuthenticator, UIKit.UIApplication application, Foundation.NSUserActivity userActivity, UIKit.UIApplicationRestorationHandler completionHandler)
        {
            var uri = userActivity?.WebPageUrl?.AbsoluteString;

            if (string.IsNullOrEmpty(uri))
            {
                return(false);
            }

            return(webAuthenticator.OpenUrl(new Uri(uri)));
        }
コード例 #4
0
        public AuthenticationController(IWebAuthenticator webAuthenticator, IConfigurationReader configurationReader)
        {
            if (webAuthenticator == null)
                throw new ArgumentNullException("webAuthenticator");

            if (configurationReader == null)
                throw new ArgumentNullException("configurationReader");

            WebAuthenticator = webAuthenticator;
            ConfigurationReader = configurationReader;
        }
コード例 #5
0
ファイル: OAuthLogin.cs プロジェクト: jvlppm/Jv.Social
        protected virtual async Task<KeyPair> GetRequestToken(IWebAuthenticator authorizer)
        {
            var oauthClient = new OAuthClient(ApplicationInfo);

            var resp = await oauthClient.Ajax(UrlGetRequestToken,
                parameters: new HttpParameters { { "oauth_callback", (await authorizer.GetCallback()).ToString() } },
                dataType: DataType.UrlEncoded
            );

            if (resp.oauth_callback_confirmed != "true")
                throw new ProtocolException("Expected oauth_callback_confirmed to be true");

            return new KeyPair(
                key: resp.oauth_token,
                secret: resp.oauth_token_secret
            );
        }
コード例 #6
0
ファイル: OAuthLogin.cs プロジェクト: jvlppm/Jv.Social
        public virtual async Task<OAuthClient> Login(IWebAuthenticator authenticator)
        {
            if (authenticator == null)
                throw new ArgumentNullException("authenticator");

            var requestToken = await GetRequestToken(authenticator);
            var userAuthResult = await GetUserAuthorization(requestToken, authenticator);

            string oAuthToken, oAuthVerifier;
            ReadUserAuthorizationResult(userAuthResult, out oAuthToken, out oAuthVerifier);

            if (requestToken.Key != oAuthToken)
                throw new ProtocolException("Invalid token authorized by server");

            var accessToken = await GetAccessToken(requestToken, oAuthVerifier);
            return new OAuthClient(ApplicationInfo, accessToken);
        }
コード例 #7
0
 public static bool OnResume(this IWebAuthenticator webAuthenticator, Android.Content.Intent intent) =>
 webAuthenticator.AsPlatformCallback().OnResumeCallback(intent);
コード例 #8
0
 public static bool OpenUrl(this IWebAuthenticator webAuthenticator, UIKit.UIApplication app, Foundation.NSUrl url, Foundation.NSDictionary options) =>
 webAuthenticator.OpenUrl(new Uri(url.AbsoluteString));
コード例 #9
0
 public static bool OpenUrl(this IWebAuthenticator webAuthenticator, Uri uri) =>
 webAuthenticator.AsPlatformCallback().OpenUrlCallback(uri);
コード例 #10
0
 public static Task <WebAuthenticatorResult> AuthenticateAsync(this IWebAuthenticator webAuthenticator, Uri url, Uri callbackUrl) =>
 webAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions {
     Url = url, CallbackUrl = callbackUrl
 });
コード例 #11
0
ファイル: OAuthLogin.cs プロジェクト: jvlppm/Jv.Social
        protected virtual Task<WebAuthenticationResult> GetUserAuthorization(KeyPair requestToken, IWebAuthenticator authorizer)
        {
            var authorizationUrlBuilder = new UriBuilder(UrlAuthorizeToken);
            authorizationUrlBuilder.AddToQuery("oauth_token", requestToken.Key);

            return authorizer.AuthorizeUser(authorizationUrlBuilder.Uri);
        }