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); }
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); }
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))); }
public AuthenticationController(IWebAuthenticator webAuthenticator, IConfigurationReader configurationReader) { if (webAuthenticator == null) throw new ArgumentNullException("webAuthenticator"); if (configurationReader == null) throw new ArgumentNullException("configurationReader"); WebAuthenticator = webAuthenticator; ConfigurationReader = configurationReader; }
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 ); }
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); }
public static bool OnResume(this IWebAuthenticator webAuthenticator, Android.Content.Intent intent) => webAuthenticator.AsPlatformCallback().OnResumeCallback(intent);
public static bool OpenUrl(this IWebAuthenticator webAuthenticator, UIKit.UIApplication app, Foundation.NSUrl url, Foundation.NSDictionary options) => webAuthenticator.OpenUrl(new Uri(url.AbsoluteString));
public static bool OpenUrl(this IWebAuthenticator webAuthenticator, Uri uri) => webAuthenticator.AsPlatformCallback().OpenUrlCallback(uri);
public static Task <WebAuthenticatorResult> AuthenticateAsync(this IWebAuthenticator webAuthenticator, Uri url, Uri callbackUrl) => webAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions { Url = url, CallbackUrl = callbackUrl });
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); }