protected void Page_Load(object sender, EventArgs e) { var context = new OAuthContextBuilder().FromHttpRequest(Request); IOAuthProvider provider = OAuthServicesLocator.Services.Provider; var tokenRepository = OAuthServicesLocator.Services.AccessTokenRepository; try { provider.AccessProtectedResourceRequest(context); var accessToken = tokenRepository.GetToken(context.Token); string userName = accessToken.UserName; var contactsDto = new { Contacts = repository.GetContactsForUser(userName), Title = string.Format("Contacts for user \"" + userName + "\"") }; Response.ContentType = "application/json"; Response.Write(JsonConvert.SerializeObject(contactsDto)); Response.End(); } catch (OAuthException authEx) { // fairly naieve approach to status codes, generally you would want to examine eiter the inner exception of the // problem report to determine an appropriate status code for your technology / architecture. Response.StatusCode = 403; Response.Write(authEx.Report); Response.End(); } }
public RedirectResult SignIn(string code, string error, string returnToUrl, string provider) { if (error != null) { return Redirect(Session["returnToUrl"].ToString()); } else if (code == null) { _oAuthProvider = getOAuthProvider(provider); if (_oAuthProvider == null) { return Redirect(returnToUrl); } Session.Add("returnToUrl", returnToUrl); Session.Add("provider", provider); return Redirect(_oAuthProvider.GetCodeUrl()); } else { _oAuthProvider = getOAuthProvider(Session["provider"].ToString()); if (_oAuthProvider == null) { return Redirect(Session["returnToUrl"].ToString()); } OAuthUser oAuthUser = _oAuthProvider.GetOAuthUser(code); Session.Add("oAuthUser", oAuthUser); return Redirect(Session["returnToUrl"].ToString()); } }
private static void InitializeProvider() { if (_provider != null) { return; } var section = ConfigurationManager.GetSection("oauth") as OAuthSection; // if there is no oauth section, then don't use this module if (section == null) { return; } var providers = new OAuthProviderCollection(); ProvidersHelper.InstantiateProviders(section.Providers, providers, typeof(OAuthProviderBase)); if ((section.DefaultProvider == null) || (providers.Count < 1)) { ThrowConfigurationError(section, "Default OAuth Provider must be specified."); } _provider = providers[section.DefaultProvider]; if (_provider == null) { ThrowConfigurationError(section, "Default OAuth Provider could not be found."); } }
public RedirectResult SignIn(string code, string error, string returnToUrl, string provider) { if (error != null) { return(Redirect(Session["returnToUrl"].ToString())); } else if (code == null) { _oAuthProvider = getOAuthProvider(provider); if (_oAuthProvider == null) { return(Redirect(returnToUrl)); } Session.Add("returnToUrl", returnToUrl); Session.Add("provider", provider); return(Redirect(_oAuthProvider.GetCodeUrl())); } else { _oAuthProvider = getOAuthProvider(Session["provider"].ToString()); if (_oAuthProvider == null) { return(Redirect(Session["returnToUrl"].ToString())); } OAuthUser oAuthUser = _oAuthProvider.GetOAuthUser(code); Session.Add("oAuthUser", oAuthUser); return(Redirect(Session["returnToUrl"].ToString())); } }
public ZzAuthenticationService(IOAuthProvider oAuthProvider , IExternalUserService exUserService, IHttpContextAccessor httpContextAccessor) { _oAuthProvider = oAuthProvider; _exUserService = exUserService; _httpContextAccessor = httpContextAccessor; }
public void Login(IOAuthProvider provider) { var userInfo = new UserInfo(); // Is the access token already set? (i.e. Remember me next time) if (!string.IsNullOrWhiteSpace (provider.AccessToken)) { try { // Get the user information from the OAuth provider. userInfo = provider.VerifyTokenAndGetUserInfo (); } catch(UnexpectedResponseException ex) { logger.Warn ("An unexpected exception occurred looking up the user's information", ex); } // If the token is invalid, the userinfo will be // non-null, but the Id will be null if (userInfo.Id == null) { // Run through the authorize procedure PerformProviderAuthorization (provider); } else { // Look up the user's TempusGameIt information GetTempusGameItUserInfo (provider.LoginUri, userInfo); } } else { PerformProviderAuthorization (provider); } }
/// <summary> /// Initializes a new instance of the <see cref="OAuth"/> class. /// </summary> /// <param name="provider">Oauth Provider</param> /// <param name="port">Port for Web server to listen. Must be the port you direct back to!</param> public OAuth(IOAuthProvider provider, int port) { _provider = provider; _httpServer = new OAuthHttpServer(port, _provider.GetSuccessUri()); _httpServer.OAuthCodeRecived += _httpServer_OAuthCodeRecived; }
public OAuthInterceptor(IOAuthProvider provider, ITokenRepository<AccessToken> repository) : base(false) { if (provider == null) throw new ArgumentNullException("provider"); if (repository == null) throw new ArgumentNullException("repository"); _provider = provider; _repository = repository; }
internal ExternalAccountPreview(IExternalUser externalUser, IOAuthProvider provider) { var pid = externalUser.ProviderId; this.Id = externalUser.Id; this.Username = externalUser.Username; this.Provider = new LoginProviderPreview(pid, provider.GetName(pid), provider.GetColour(pid)); }
public SportsProvider(string appUrl, string consumerKey, string consumerSecret, AccessToken token = null, string oauthCallback = OAuthConstants.DEFAULT_CALLBACK) { AppUrl = appUrl; ConsumerKey = consumerKey; ConsumerSecret = consumerSecret; Token = token; IsAuthenticated = token != null; oauthProvider = new YahooOAuthProvider(consumerKey, consumerSecret, appUrl, oauthCallback); }
public UserService(IOAuthProvider oauthProvider) { if (oauthProvider == null) { throw new ArgumentNullException(nameof(oauthProvider)); } _oauthProvider = oauthProvider; }
public OAuthHandler(IOAuthProvider oauthProvider, HttpMessageHandler innerHandler) : base(innerHandler) { if (oauthProvider == null) { throw new ArgumentNullException(nameof(oauthProvider)); } _oauthProvider = oauthProvider; }
protected void Page_Load(object sender, EventArgs e) { IOAuthContext context = new OAuthContextBuilder().FromHttpRequest(Request); IOAuthProvider provider = OAuthServicesLocator.Provider; IToken token = provider.GrantRequestToken(context); Response.Write(token); Response.End(); }
/// <summary> /// Retrieve controller instance appropriate for the designated provider. /// </summary> /// <param name="providerId"></param> /// <returns></returns> public static AuthorizationServiceViewControllerBase GetAuthorizationServiceViewController(String providerId) { IOAuthProvider provider = EntityFactory.GetById <IOAuthProvider>(providerId); if (provider.OAuthVersion == "1.0") { return(new OAuth1AuthorizationServiceViewController(provider)); } // default to OAuth 2 return(new OAuth2AuthorizationServiceViewController(provider)); }
public void CreateProvider_OnGoogle_ReturnsGoogleAuthentication() { // ARRANGE AuthenticationFactory factory = new AuthenticationFactory(); // ACT IOAuthProvider provider = factory.CreateProvider(AuthenticationProvider.Google); // ASSERT provider.Should().BeOfType(typeof(GoogleAuthentication)); }
public void ShowDialog(ScrumFactory.Services.AuthProviders.IOAuthProvider provider) { if (provider == null) return; this.provider = provider; this.Title = provider.ProviderName; this.badLogin.Text = String.Format(Properties.Resources.bad_login, provider.ProviderName); this.badLogin.Visibility = Visibility.Collapsed; this.ShowDialog(); }
public async Task <FileSystemResult <IFileSystem> > InitAsync(string fname, IOAuthProvider provider, Dictionary <string, object> settings, string userauthorization = null) { FileSystemResult <OneDriveFileSystem> r = await OneDriveFileSystem.Create(fname, provider, settings, Name, userauthorization); if (!r.IsOk) { return(new FileSystemResult <IFileSystem>(r.Error)); } OneDriveFileSystem f = r.Result; return(new FileSystemResult <IFileSystem>(f)); }
public OController() { oAuthContextBuilder = new OAuthContextBuilder(); tr = new MVC.Sample.Models.TokenRepository(); tokenstore = new MVC.Sample.Models.SampleMemoryTokenStore(tr); iCStore = new SampleConsumerStore(); Inspector = new ConsumerValidationInspector(iCStore); oAuthProvider = new OAuthProvider(tokenstore, Inspector); target = new OAuthController(oAuthContextBuilder, oAuthProvider); }
public void OAuthInintializer_InitializeTest() { //Arrange string providerName = "facebook"; //Act _inintializer.Initialize(); //Assert IOAuthProvider provider = _oAuthService[providerName]; Assert.IsNotNull(provider); Assert.AreEqual(provider.ProviderName, providerName); }
public JsonResult AddOAuth(int type) { if (IoCFactory.Instance.TryResolve <IFormAuthentication>().IsAuthentication()) { return(IncRedirectToAction("Index", "Browsio")); } var connectorOfType = (ConnectorOfType)type; IOAuthProvider oAuthProvider = IoCFactory.Instance.TryResolveByNamed <IOAuthProvider>(connectorOfType.ToString()); var callbackUrl = GetCallbackOauthUri(connectorOfType); return(IncRedirect(oAuthProvider.GetAuthorizationUri(callbackUrl))); }
public OAuthInterceptor(IOAuthProvider provider, ITokenRepository <AccessToken> repository) : base(false) { if (provider == null) { throw new ArgumentNullException("provider"); } if (repository == null) { throw new ArgumentNullException("repository"); } _provider = provider; _repository = repository; }
static OAuthServicesLocator() { var consumerStore = new TestConsumerStore(); var nonceStore = new TestNonceStore(); _accessTokenRepository = new InMemoryTokenRepository<DevDefined.OAuth.Storage.Basic.AccessToken>(); _requestTokenRepository = new InMemoryTokenRepository<DevDefined.OAuth.Storage.Basic.RequestToken>(); var tokenStore = new SimpleTokenStore(_accessTokenRepository, _requestTokenRepository); _provider = new OAuthProvider(tokenStore, new SignatureValidationInspector(consumerStore), new NonceStoreInspector(nonceStore), new TimestampRangeInspector(new TimeSpan(1, 0, 0)), new ConsumerValidationInspector(consumerStore)); }
public async Task <FileSystemResult <IFileSystem> > InitAsync(string fname, IOAuthProvider provider, Dictionary <string, object> settings, string userauthorization = null) { FileSystemResult <GoogleDriveFileSystem> r = await GoogleDriveFileSystem.Create(fname, provider, settings, Name, userauthorization); if (!r.IsOk) { return(new FileSystemResult <IFileSystem>(r.Error)); } GoogleDriveFileSystem f = r.Result; if (settings.ContainsKey(AcknowledgeAbuse) && (settings[AcknowledgeAbuse] is bool)) { f.AckAbuse = (bool)settings[AcknowledgeAbuse]; } return(new FileSystemResult <IFileSystem>(f)); }
/// <summary> /// Autentykuje użytkownika po przez wskazanego providera /// </summary> /// <param name="provider">Dostawca autentykacji</param> /// <returns>Konto użytkownika. Null jeśli nie udało się uwierzytelnić</returns> public async Task <UserPublic> AuthenticateAsync(AuthenticationProvider provider, CancellationToken cancellationToken) { AuthenticationFactory factory = new AuthenticationFactory(); mProvider = factory.CreateProvider(provider); CredentialsManager credentialsManager = new CredentialsManager(provider); string refreshToken = credentialsManager.LoadToken(); if (!string.IsNullOrEmpty(refreshToken)) { return(await mProvider.RefreshUserAsync(refreshToken, cancellationToken).ConfigureAwait(false)); } return(await mProvider.AuthenticateUserAsync(cancellationToken).ConfigureAwait(false)); }
static OAuthServicesLocator() { var consumerStore = new TestConsumerStore(); var nonceStore = new TestNonceStore(); _accessTokenRepository = new InMemoryTokenRepository <DevDefined.OAuth.Storage.Basic.AccessToken>(); _requestTokenRepository = new InMemoryTokenRepository <DevDefined.OAuth.Storage.Basic.RequestToken>(); var tokenStore = new SimpleTokenStore(_accessTokenRepository, _requestTokenRepository); _provider = new OAuthProvider(tokenStore, new SignatureValidationInspector(consumerStore), new NonceStoreInspector(nonceStore), new TimestampRangeInspector(new TimeSpan(1, 0, 0)), new ConsumerValidationInspector(consumerStore)); }
protected void Application_Start(object sender, EventArgs e) { _requestTokenRepository = new InMemoryTokenRepository <DevDefined.OAuth.Storage.Basic.RequestToken>(); _accessTokenRepository = new InMemoryTokenRepository <DevDefined.OAuth.Storage.Basic.AccessToken>(); var consumerStore = new JiraConsumerStore(); var nonceStore = new TestNonceStore(); var tokenStore = new SimpleTokenStore(_accessTokenRepository, _requestTokenRepository); _provider = new OAuthProvider(tokenStore, new SignatureValidationInspector(consumerStore), new NonceStoreInspector(nonceStore), new TimestampRangeInspector(new TimeSpan(1, 0, 0)), new ConsumerValidationInspector(consumerStore) /*,new OAuth10AInspector(tokenStore)*/); }
protected void Application_Start(object sender, EventArgs e) { _requestTokenRepository = new InMemoryTokenRepository<DevDefined.OAuth.Storage.Basic.RequestToken>(); _accessTokenRepository = new InMemoryTokenRepository<DevDefined.OAuth.Storage.Basic.AccessToken>(); var consumerStore = new JiraConsumerStore(); var nonceStore = new TestNonceStore(); var tokenStore = new SimpleTokenStore(_accessTokenRepository, _requestTokenRepository); _provider = new OAuthProvider(tokenStore, new SignatureValidationInspector(consumerStore), new NonceStoreInspector(nonceStore), new TimestampRangeInspector(new TimeSpan(1, 0, 0)), new ConsumerValidationInspector(consumerStore) /*,new OAuth10AInspector(tokenStore)*/); }
public void SetFixture(MockRepository mocks) { mockRepository = mocks; DefaultProvider = mocks.DynamicMock <IOAuthProvider>(); DefaultcontextBuilder = mocks.DynamicMock <IOAuthContextBuilder>(); var httpRequest = mocks.DynamicMock <HttpRequestBase>(); var httpContextMock = mocks.DynamicMock <HttpContextBase>(); mockOAuthContext = mocks.DynamicMock <IOAuthContext>(); DefaultcontextBuilder.Stub(contextBuilder => contextBuilder.FromHttpRequest(httpRequest)).Return(mockOAuthContext); DefaultProvider.Stub(provider => provider.ExchangeRequestTokenForAccessToken(mockOAuthContext)).Return(requestToken); httpContextMock.Stub(httpcontext => httpcontext.Request).Return(httpRequest); var controller = new OAuthController(ContextBuilder, Provider); var controllerContext = new ControllerContext(httpContextMock, new RouteData(), controller); controller.ControllerContext = controllerContext; mocks.ReplayAll(); result = controller.AccessToken(); }
/// <summary> /// Tworzy dostawcę autentykacji /// </summary> /// <param name="authProvider">Typ dostawcy autentykacji</param> /// <returns>Dostawca autentykacji</returns> public virtual IOAuthProvider CreateProvider(AuthenticationProvider authProvider) { IOAuthProvider provider = null; switch (authProvider) { case AuthenticationProvider.Google: provider = new GoogleAuthentication(); break; case AuthenticationProvider.Microsoft: provider = new MicrosoftAuthentication(); break; default: break; } return(provider); }
public ConsumerFactory(ConsumerOptions consumerOptions,IOAuthProvider provider) { if (string.IsNullOrEmpty(consumerOptions.ConsumerKey)) throw new ArgumentNullException("ConsumerKey"); if (string.IsNullOrEmpty(consumerOptions.ConsumerSecret)) throw new ArgumentNullException("ConsumerSecret"); if (string.IsNullOrEmpty(consumerOptions.RequestTokenUrl)) throw new ArgumentNullException("RequestTokenUrl"); if (string.IsNullOrEmpty(consumerOptions.AccessTokenUrl)) throw new ArgumentNullException("AccessTokenUrl"); if (string.IsNullOrEmpty(consumerOptions.RequestTokenResponseCallbackUrl)) throw new ArgumentNullException("RequestTokenResponseCallbackUrl"); this.provider = provider; ConsumerOptions = consumerOptions; }
protected void Page_Load(object sender, EventArgs e) { try { IOAuthContext context = new OAuthContextBuilder().FromHttpRequest(Request); IOAuthProvider provider = OAuthServicesLocator.Services.Provider; IToken token = provider.GrantRequestToken(context); Response.Write(token); } catch (OAuthException ex) { Response.StatusCode = 400; Response.Write(ex.Report.ToString()); } Response.End(); }
public async Task <FileSystemResult <IFileSystem> > InitAsync(string fname, IOAuthProvider provider, Dictionary <string, object> settings, string userauthorization = null) { string frname; if (settings.ContainsKey(ClientAppFriendlyName) && (settings[ClientAppFriendlyName] is string)) { frname = (string)settings[ClientAppFriendlyName]; } else { return(new FileSystemResult <IFileSystem>("Unable to find " + fname + " '" + ClientAppFriendlyName + "' in settings")); } FileSystemResult <AmazonFileSystem> r = await AmazonFileSystem.Create(fname, provider, settings, Name, userauthorization); if (!r.IsOk) { return(new FileSystemResult <IFileSystem>(r.Error)); } r.Result.AppFriendlyName = frname; return(new FileSystemResult <IFileSystem>(r.Result)); }
private static void InitializeProvider() { if (_provider != null) return; var section = ConfigurationManager.GetSection("oauth") as OAuthSection; // if there is no oauth section, then don't use this module if (section == null) return; var providers = new OAuthProviderCollection(); ProvidersHelper.InstantiateProviders(section.Providers, providers, typeof(OAuthProviderBase)); if ((section.DefaultProvider == null) || (providers.Count < 1)) ThrowConfigurationError(section, "Default OAuth Provider must be specified."); _provider = providers[section.DefaultProvider]; if (_provider == null) ThrowConfigurationError(section, "Default OAuth Provider could not be found."); }
protected void Page_Load(object sender, EventArgs e) { try { IOAuthContext context = new OAuthContextBuilder().FromHttpRequest(Request); IOAuthProvider provider = OAuthServicesLocator.Services.Provider; IToken accessToken = provider.ExchangeRequestTokenForAccessToken(context); Response.Write(accessToken); } catch (OAuthException ex) { // fairly naieve approach to status codes, generally you would want to examine either the inner exception or the // problem report to determine an appropriate status code for your technology / architecture. Response.StatusCode = 400; Response.Write(ex.Report.ToString()); } Response.End(); }
public void SetFixture(MockRepository mocks) { AuthFiliter = new OAuthSecuredAttribute(); DefaultoAuthContextBuilder = mocks.DynamicMock <IOAuthContextBuilder>(); DefaultoAuthPovider = mocks.DynamicMock <IOAuthProvider>(); var controllerBase = mocks.DynamicMock <ControllerBase>(); var httpContext = mocks.DynamicMock <HttpContextBase>(); var mockHttpRequest = mocks.DynamicMock <HttpRequestBase>(); DefaultoAuthContext = mocks.DynamicMock <IOAuthContext>(); var controllerContext = new ControllerContext(httpContext, new RouteData(), controllerBase); httpContext.Stub(context => context.Request).Return(mockHttpRequest); DefaultoAuthContextBuilder.Stub(contextBuilder => contextBuilder.FromHttpRequest(mockHttpRequest)).Return(OAuthContext); SetupExpectations(); FilterContext = new AuthorizationContext(controllerContext); AuthFiliter.OAuthContextBuilder = OAuthContextBuilder; AuthFiliter.OAuthProvider = OAuthPovider; mocks.ReplayAll(); Exception = Record.Exception(() => AuthFiliter.OnAuthorization(FilterContext)); }
/// <summary> /// Initializes a new instance of the <see cref="OAuthIdentityBase"/> class. /// </summary> protected OAuthIdentityBase(IOAuthProvider provider) { Provider = provider; }
public ExternalLoginResult(IOAuthProvider oAuthProvider, string provider, string returnUrl) { _oAuthProvider = oAuthProvider; Provider = provider; ReturnUrl = returnUrl; }
// Constructor for standard OAuth public OAuthAuthorizer(IOAuthProvider provider) { this.provider = provider; }
public OAuth1AuthorizationServiceViewController(IOAuthProvider provider) : base(provider) { }
public OAuthController(IOAuthContextBuilder oAuthContextBuilder,IOAuthProvider oAuthProvider) { _oAuthContextBuilder = oAuthContextBuilder; _oAuthProvider = oAuthProvider; }
public OAuth1AuthorizationServiceViewController(IOAuthProvider provider) : base(provider) { }
public OAuthHandler(IOAuthProvider oauthProvider) : this(oauthProvider, new HttpClientHandler()) { }
protected AuthorizationServiceViewControllerBase(IOAuthProvider provider) { this.provider = provider; }
/// <summary> /// Initializes a new instance of the <see cref="OAuthAuthenticationEventArgs"/> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="identity">The identity.</param> /// <param name="context">The context.</param> public OAuthAuthenticationEventArgs(IOAuthProvider provider, IIdentity identity, HttpContext context) { Identity = identity; Context = context; Provider = provider; }
public async Task <FileSystemResult <IFileSystem> > InitAsync(string fname, IOAuthProvider provider, Dictionary <string, object> authorization, string userauthorization = null) { return(await LocalFileSystem.Create(string.Empty)); }
void PerformLogin(IOAuthProvider provider, string providerName) { try { AuthenticationProvider = providerName; authentication.Login (provider); if(Authentication.Token == null) return; DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { logger.Error (ex); HandleFailure (ex.Message); } }
public Principal(IOAuthProvider provider, IIdentity identity) : base(provider, identity) { }
public Identity(IOAuthProvider provider, string token) : base(provider) { Token = token; Realm = "hi5-auth"; }
public ProviderHelperItem(IOAuthProvider provider) { _provider = provider; }
/// <summary> /// Initializes a new instance of the <see cref="OAuthPrincipalBase"/> class. /// </summary> /// <param name="identity">The identity.</param> protected OAuthPrincipalBase(IOAuthProvider provider, IIdentity identity) { Provider = provider; Identity = identity; }
public DemoIdentity(IOAuthProvider provider, string token) : base(provider) { Token = token; Realm = "Demo"; }
public static async Task <FileSystemResult <OneDriveFileSystem> > Create(string fname, IOAuthProvider provider, Dictionary <string, object> settings, string pluginanme, string userauthorization = null) { OneDriveFileSystem am = new OneDriveFileSystem(provider); am.FS = am; am.OAuth.OAuthUrl = OneDriveOAuth; am.OAuth.EndPointUrl = null; am.OAuth.OAuthLoginUrl = OneDriveOAuthLogin; am.OAuth.DefaultScopes = OneDriveScopes; bool userauth = !string.IsNullOrEmpty(userauthorization); if (userauth) { am.DeserializeAuth(userauthorization); } FileSystemResult r = await am.OAuth.Login(settings, pluginanme, userauth, true); if (!r.IsOk) { return(new FileSystemResult <OneDriveFileSystem>(r.Error)); } r = await am.OAuth.MayRefreshToken(); if (!r.IsOk) { return(new FileSystemResult <OneDriveFileSystem>(r.Error)); } r = await am.QuotaAsync(); if (!r.IsOk) { return(new FileSystemResult <OneDriveFileSystem>(r.Error)); } r = await am.PopulateAsync(); if (!r.IsOk) { return(new FileSystemResult <OneDriveFileSystem>(r.Error)); } return(new FileSystemResult <OneDriveFileSystem>(am)); }
void PerformProviderAuthorization( IOAuthProvider provider ) { try { var deviceProvider = provider as IDeviceOAuthProvider; var offlineProvider = provider as IOfflineOAuthProvider; if (deviceProvider != null) { Authorize (deviceProvider); } if (offlineProvider != null) { Authorize (offlineProvider); } } catch (UnexpectedResponseException ex) { logger.Fatal (ex); if (Failure != null) Failure (this, new AuthenticationErrorEventArgs ("An error occurred authenticating your credentials", ex)); } catch (AuthenticationException) { throw; } catch (Exception ex) { logger.Fatal (ex); const string message = "An unknown error occurred attempting to log in. Make sure you are online, and you've created an account on the TempusGameIt website."; if (Error != null) Error (this, new AuthenticationErrorEventArgs (message, ex)); } }