public Generate ( string accessKey = null ) : string | ||
accessKey | string | The access key used to sign the app token |
return | string |
public void CreateGenericTokenWithMissingParamsFails() { var token = new PowerBIToken { Issuer = null, Audience = null }; token.Generate(this.accessKey); }
public void CreateGenericTokenWithInvalidExpirationFails() { var token = new PowerBIToken { Issuer = "issuer", Audience = "audience", AccessKey = this.accessKey, Expiration = DateTime.MinValue }; token.Generate(); }
public void CanManuallyCreatePowerBIToken() { var token = new PowerBIToken { Audience = "TestAudience", Issuer = "TestIssuer", Expiration = DateTime.UtcNow.AddHours(2), AccessKey = this.accessKey }; token.Claims.Add(new Claim("Name", "TestUser")); var jwt = token.Generate(); var decodedToken = new JwtSecurityToken(jwt); var tokenExpiration = new DateTime( token.Expiration.Value.Year, token.Expiration.Value.Month, token.Expiration.Value.Day, token.Expiration.Value.Hour, token.Expiration.Value.Minute, token.Expiration.Value.Second); Assert.IsTrue(decodedToken.Audiences.Contains(token.Audience)); Assert.AreEqual(token.Issuer, decodedToken.Issuer); Assert.AreEqual(tokenExpiration, decodedToken.ValidTo); var nameClaim = decodedToken.Claims.FirstOrDefault(c => c.Type == "Name"); Assert.AreEqual("TestUser", nameClaim.Value); }
protected IPowerBIClient CreatePowerBIClient(PowerBIToken token) { var jwt = token.Generate(accessKey); var credentials = new TokenCredentials(jwt, "AppToken"); var client = new PowerBIClient(credentials) { BaseUri = new Uri(apiUrl) }; return client; }
private static IPowerBIClient CreatePowerBiClient(PowerBIToken token) { var jwt = token.Generate(ConfigHelper.PowerbiSigningKey); var credentials = new TokenCredentials(jwt, "AppToken"); var client = new PowerBIClient(credentials) { BaseUri = new Uri(ConfigHelper.PowerbiApiUrl) }; return client; }
static IPowerBIClient CreateClient(PowerBIToken token, string accessKey, string apiUrl) { WorkspaceCollectionKeys accessKeys = new WorkspaceCollectionKeys() { Key1 = accessKey }; // Generate a JWT token used when accessing the REST APIs var jwt = token.Generate(accessKeys.Key1); // Create a token credentials with "AppToken" type var credentials = new TokenCredentials(jwt, "AppToken"); // Instantiate your Power BI client passing in the required credentials var client = new PowerBIClient(credentials); // Override the api endpoint base URL. Default value is https://api.powerbi.com client.BaseUri = new Uri(apiUrl); return client; }