public static TokenCredentials GenerateTokenCredentials( this IAuthenticationManager authenticationManager, AuthenticationResult authenticationResult ) { ITokenProvider tokenProvider = new StringTokenProvider(authenticationResult.AccessToken, "Bearer"); var tenantId = authenticationManager.GetTenantId(); var account = authenticationManager.GetAccount(); TokenCredentials tokenCredentials; // Some authentication flows result in null account. if (null != tenantId && null != account?.Username) { tokenCredentials = new TokenCredentials( tokenProvider, tenantId.ToString(), account.Username ); } else { tokenCredentials = new TokenCredentials(tokenProvider); } return(tokenCredentials); }
public void Should_Throw_ArgumentException_WrongBeginning() { var provider = new StringTokenProvider(); var expression = "name = 'asdf' and amount < 43 and comment contains 'vyber"; Assert.Throws <ArgumentException>(() => provider.GetToken(1, expression)); }
public void Should_Provide_Token() { var provider = new StringTokenProvider(); var expression = "name = 'tata' and amount < 43 and comment contains 'vyber'"; var result = provider.GetToken(7, expression); Assert.Equal(7, result.StartIndex); Assert.Equal(12, result.EndIndex); Assert.IsType <StringToken>(result.Token); Assert.Equal("tata", result.Token.Value); }
public void Should_Provide_Token_With_Apostrophes() { var provider = new StringTokenProvider(); var expression = "name = 'asdf' and amount < 43 and comment contains 'what''s''up ''''with that'''''"; var result = provider.GetToken(51, expression); Assert.Equal(51, result.StartIndex); Assert.Equal(81, result.EndIndex); Assert.IsType <StringToken>(result.Token); Assert.Equal("what's'up ''with that''", result.Token.Value); }
protected MonitorManagementClient GetMonitorManagementClient(RecordedDelegatingHandler handler) { handler.IsPassThrough = false; var tokenProvider = new StringTokenProvider("granted", "SimpleString"); var id = Guid.NewGuid().ToString(); var token = new TokenCredentials(tokenProvider: tokenProvider, tenantId: id, callerId: id); var client = new MonitorManagementClient(token, handler); token.InitializeServiceClient(client); client.SubscriptionId = id; return(client); }
public static TokenCredentials GenerateTokenCredentials( AuthenticationResult authenticationResult ) { ITokenProvider tokenProvider = new StringTokenProvider(authenticationResult.AccessToken, "Bearer"); var tokenCredentials = new TokenCredentials( tokenProvider, authenticationResult.TenantId, authenticationResult.Account.Username ); return(tokenCredentials); }