Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I Register a Web Application and Authenticate a Web Application, AccessToken's Lifetime? Thank you.
protected void signInButton_Click(object sender, EventArgs e) { //Create a query string //Create a sign-in NameValueCollection for query string var @params = new NameValueCollection { //Azure AD will return an authorization code. //See the Redirect class to see how "code" is used to AcquireTokenByAuthorizationCode {"response_type", "code"}, //Client ID is used by the application to identify themselves to the users that they are requesting permissions from. //You get the client id when you register your Azure app. {"client_id", Properties.Settings.Default.ClientID}, //Resource uri to the Power BI resource to be authorized {"resource", "https://analysis.windows.net/powerbi/api"}, //After user authenticates, Azure AD will redirect back to the web app {"redirect_uri", "http://localhost:13526/Redirect"} }; //Create sign-in query string var queryString = HttpUtility.ParseQueryString(string.Empty); queryString.Add(@params); //Redirect authority //Authority Uri is an Azure resource that takes a client id to get an Access token string authorityUri = "https://login.windows.net/common/oauth2/authorize/"; Response.Redirect(String.Format("{0}?{1}", authorityUri, queryString)); } public partial class Redirect : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //Redirect uri must match the redirect_uri used when requesting Authorization code. string redirectUri = "http://localhost:13526/Redirect"; string authorityUri = "https://login.windows.net/common/oauth2/authorize/"; // Get the auth code string code = Request.Params.GetValues(0)[0]; // Get auth token from auth code TokenCache TC = new TokenCache(); AuthenticationContext AC = new AuthenticationContext(authorityUri, TC); ClientCredential cc = new ClientCredential (Properties.Settings.Default.ClientID, Properties.Settings.Default.ClientSecret); AuthenticationResult AR = AC.AcquireTokenByAuthorizationCode(code, new Uri(redirectUri), cc); //Set Session "authResult" index string to the AuthenticationResult Session["authResult"] = AR; //Redirect back to Default.aspx Response.Redirect("/Default.aspx"); } } public partial class _Default : Page { public AuthenticationResult authResult { get; set; } string baseUri = "https://api.powerbi.com/beta/myorg/"; protected void Page_Load(object sender, EventArgs e) { //Test for AuthenticationResult if (Session["authResult"] != null) { //Get the authentication result from the session authResult = (AuthenticationResult)Session["authResult"]; //Show Power BI Panel signInStatus.Visible = true; //Set user and token from authentication result userLabel.Text = authResult.UserInfo.DisplayableId; accessTokenTextbox.Text = authResult.AccessToken; } } ... }
Solved! Go to Solution.
@xuandungpy wrote:I Register a Web Application and Authenticate a Web Application, AccessToken's Lifetime? Thank you.
By default, the token expires in one hour. You can find the expire time("exp" field) after decoding the token.
how was this solved?
want to increase the token lifetime to 1 day.
how can I do that?
Thanks,
Alex
Hey, Can You Tell how actually you solved from the above sample code.
I want to increase the exp time to 1 day and also want to know how you solved this problem
@xuandungpy wrote:I Register a Web Application and Authenticate a Web Application, AccessToken's Lifetime? Thank you.
By default, the token expires in one hour. You can find the expire time("exp" field) after decoding the token.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
6 | |
6 | |
3 | |
2 | |
2 |
User | Count |
---|---|
6 | |
5 | |
4 | |
4 | |
3 |