<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic AccessToken lifetime from web app in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/AccessToken-lifetime-from-web-app/m-p/160607#M5402</link>
    <description>&lt;P&gt;I Register a Web Application and Authenticate a Web Application, AccessToken's Lifetime? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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);

      &lt;STRONG&gt;&lt;FONT color="#FF0000" size="4"&gt;AuthenticationResult AR = AC.AcquireTokenByAuthorizationCode(code, new Uri(redirectUri), cc);&lt;/FONT&gt;&lt;/STRONG&gt;

      //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;
      }
  }

  ...
}

 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Apr 2017 18:06:21 GMT</pubDate>
    <dc:creator>xuandungpy</dc:creator>
    <dc:date>2017-04-18T18:06:21Z</dc:date>
    <item>
      <title>AccessToken lifetime from web app</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/AccessToken-lifetime-from-web-app/m-p/160607#M5402</link>
      <description>&lt;P&gt;I Register a Web Application and Authenticate a Web Application, AccessToken's Lifetime? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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);

      &lt;STRONG&gt;&lt;FONT color="#FF0000" size="4"&gt;AuthenticationResult AR = AC.AcquireTokenByAuthorizationCode(code, new Uri(redirectUri), cc);&lt;/FONT&gt;&lt;/STRONG&gt;

      //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;
      }
  }

  ...
}

 &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 18:06:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/AccessToken-lifetime-from-web-app/m-p/160607#M5402</guid>
      <dc:creator>xuandungpy</dc:creator>
      <dc:date>2017-04-18T18:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: AccessToken lifetime from web app</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/AccessToken-lifetime-from-web-app/m-p/161599#M5427</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/27003"&gt;@xuandungpy&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;I Register a Web Application and Authenticate a Web Application, &lt;STRONG&gt;AccessToken's Lifetime&lt;/STRONG&gt;? Thank you.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/27003"&gt;@xuandungpy&lt;/a&gt;&lt;/P&gt;&lt;P&gt;By default, the token expires in one hour. You can find the expire time("exp" field) after &lt;A href="https://jwt.io" target="_self"&gt;decoding the token&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.technet.microsoft.com/enterprisemobility/2016/10/11/configurable-token-lifetimes-in-azuread-are-now-public-preview/" target="_self"&gt;Check more&amp;nbsp;Configurable token lifetimes in #AzureAD&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 01:00:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/AccessToken-lifetime-from-web-app/m-p/161599#M5427</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-04-20T01:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: AccessToken lifetime from web app</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/AccessToken-lifetime-from-web-app/m-p/207207#M6564</link>
      <description>&lt;P&gt;Hey, Can You Tell how actually you solved from the above sample code.&lt;/P&gt;&lt;P&gt;I want to increase the exp time to 1 day and also want to know how you solved this problem&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 09:55:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/AccessToken-lifetime-from-web-app/m-p/207207#M6564</guid>
      <dc:creator>Supraj</dc:creator>
      <dc:date>2017-07-06T09:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: AccessToken lifetime from web app</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/AccessToken-lifetime-from-web-app/m-p/313816#M9280</link>
      <description>&lt;P&gt;how was this solved?&lt;/P&gt;&lt;P&gt;want to increase the token lifetime to 1 day.&lt;/P&gt;&lt;P&gt;how can I do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 13:26:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/AccessToken-lifetime-from-web-app/m-p/313816#M9280</guid>
      <dc:creator>izurev</dc:creator>
      <dc:date>2017-11-29T13:26:00Z</dc:date>
    </item>
  </channel>
</rss>

