Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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.
User | Count |
---|---|
15 | |
2 | |
1 | |
1 | |
1 |
User | Count |
---|---|
17 | |
11 | |
5 | |
4 | |
3 |