public ActionResult RefreshToken() { string refreshToken = CustomAuthenticationManager.GetRefreshToken(); JwtSecurityToken jwtRefreshToken = new JwtSecurityToken(refreshToken); return(View(jwtRefreshToken)); }
public ActionResult AccessToken() { string accessToken = CustomAuthenticationManager.GetAccessToken(); JwtSecurityToken jwtAccessToken = new JwtSecurityToken(accessToken); return(View(jwtAccessToken)); }
public ActionResult IdToken() { string idToken = CustomAuthenticationManager.GetIdToken(); JwtSecurityToken jwtIdToken = new JwtSecurityToken(idToken); return(View(jwtIdToken)); }
public ActionResult Index(string code) { CustomAuthenticationManager.CacheAuthenticationCode(code); ClientCredential credential = new ClientCredential(DemoConstants.ClientId, DemoConstants.ClientSecret); string resource = DemoConstants.TargetResource; Uri uriReplyUrl = new Uri(DemoConstants.ClientReplyUrl); AuthenticationContext authenticationContext = new AuthenticationContext(DemoConstants.urlAuthorizationEndpoint); AuthenticationResult authenticationResult = authenticationContext.AcquireTokenByAuthorizationCode( code, uriReplyUrl, credential, resource); CustomAuthenticationManager.CacheAuthenticationResult(authenticationResult); ViewBag.AuthenticationCode = code; return(View(authenticationResult)); }
public ActionResult Index() { string tenantId = CustomAuthenticationManager.GetTenantID(); string userId = CustomAuthenticationManager.GetUserID(); string urlRestTemplate = "https://graph.windows.net/{0}/users/{1}?api-version=1.5"; string urlRest = string.Format(urlRestTemplate, tenantId, userId); Uri uriRest = new Uri(urlRest); string accessToken = CustomAuthenticationManager.GetAccessToken(); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken); client.DefaultRequestHeaders.Add("Accept", "application/json"); HttpResponseMessage response = client.GetAsync(uriRest).Result; if (response.IsSuccessStatusCode) { string json = response.Content.ReadAsStringAsync().Result; ADUser userInfo = JObject.Parse(json).ToObject <ADUser>(); return(View(userInfo)); } else { throw new ApplicationException("Whoops"); } }
public ActionResult RefreshAccessToken() { string refreshToken = CustomAuthenticationManager.GetRefreshToken(); ClientCredential credential = new ClientCredential(DemoConstants.ClientId, DemoConstants.ClientSecret); string resource = DemoConstants.TargetResource; AuthenticationContext authenticationContext = new AuthenticationContext(DemoConstants.urlAuthorizationEndpoint); AuthenticationResult authenticationResult = authenticationContext.AcquireTokenByRefreshToken(refreshToken, credential, resource); CustomAuthenticationManager.RefreshAccessToken(authenticationResult); return(RedirectToAction("AccessToken", "TokenViewer")); }
public ActionResult AppOnlyAccessToken() { string urlTokenEndpointForTenant = string.Format("https://login.windows.net/{0}/oauth2/token", CustomAuthenticationManager.GetTenantID()); ADAL.AuthenticationContext authenticationContext = new ADAL.AuthenticationContext(urlTokenEndpointForTenant); string resource = DemoConstants.TargetResource; ADAL.ClientAssertionCertificate clientAssertionCertificate = DemoConstants.GetClientAssertionCertificate(); ADAL.AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resource, clientAssertionCertificate); string appOnlyAccessToken = authenticationResult.AccessToken; JwtSecurityToken jwtAppOnlyAccessToken = new JwtSecurityToken(appOnlyAccessToken); return(View(jwtAppOnlyAccessToken)); }
public ActionResult SignOut() { CustomAuthenticationManager.ClearTokenCache(); return(RedirectToAction("Index", "Home")); }