/// <summary> /// Initializes connection information for the repository. Should /// always be called before any other methods. /// </summary> /// <param name="endpoint">URL of the API endpoint</param> /// <param name="providerType">Type of provider only oAuth implemented</param> /// <param name="clientAppKey">App token</param> /// <param name="clientAppSecret">App secret</param> /// <param name="clientAuthToken">May be blank, but if blank auth token should be retrieved and set using SetAuthData before other calls are made.</param> /// <param name="clientAuthSecret">May be blank, but if blank auth secret should be retrieved and set using SetAuthData before other calls are made.</param> public void Initialize(string endpoint, string wellknown, RemoteProviderType providerType, TokenRefreshHandler refreshHandler, TokenExpiredCheckHandler expireHandler, string clientAppKey = "", string clientAppSecret = "", string accessToken = "", string refreshToken = "") { _endpoint = endpoint; _wellKnown = wellknown; _refreshHandler = refreshHandler; _expireCheckHandler = expireHandler; ApiCredentials.APP_ID = clientAppKey; ApiCredentials.APP_KEY = clientAppSecret; ApiCredentials.ACCESS_TOKEN = accessToken; ApiCredentials.REFRESH_TOKEN = refreshToken; }
public async Task DontRefreshTokenWhenTokenIsInvalid() { var options = Options.Create <AuthOptions>(new AuthOptions()); var logger = new TestLogger <TokenRefreshHandler>(); var tokenRefreshAgentMock = new Mock <ITokenRefreshAgent>(); var tokenRefreshHandler = new TokenRefreshHandler(options, tokenRefreshAgentMock.Object, logger); var jwt = "abc.123.456"; await tokenRefreshHandler.HandleRefreshAsync(jwt); tokenRefreshAgentMock.Verify(a => a.RefreshTokenAsync(jwt), Times.Never); Assert.Equal(1, logger.LoggedMessages.Count); Assert.Contains("Invalid jwt refresh request. token:", logger.LoggedMessages.First()); }
public async Task DontRefreshTokenWhenAudienceDontMatch() { var options = Options.Create <AuthOptions>(new AuthOptions() { JwtAudience = "audience" }); var logger = new TestLogger <TokenRefreshHandler>(); var tokenRefreshAgentMock = new Mock <ITokenRefreshAgent>(); var tokenRefreshHandler = new TokenRefreshHandler(options, tokenRefreshAgentMock.Object, logger); var jwtHandler = new JwtSecurityTokenHandler(); var jwt = jwtHandler.CreateEncodedJwt(new SecurityTokenDescriptor() { Expires = DateTime.Now.AddMinutes(-1) }); await tokenRefreshHandler.HandleRefreshAsync(jwt); tokenRefreshAgentMock.Verify(a => a.RefreshTokenAsync(jwt), Times.Never); }
public void SetTokenRefreshHandler(TokenRefreshHandler handler) { _refreshHandler = handler; }