static void Authenticate() { var authorizeClient = new IdentityModel.Client.AuthorizeRequest("https://100.105.80.38:13855/connect/authorize"); var url = authorizeClient.CreateAuthorizeUrl( clientId: "silicon", responseType: "code id_token token", scope: "openid offline_access", redirectUri: "http://*****:*****@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe", "-private-window \"" + url + "\""); //Console.WriteLine(client.GetStringAsync(url).Result); }
private static string RequestAccessTokenAuthorizationCode() { //did we store the token before? var cookie = HttpContext.Current.Request.Cookies.Get("tripGalleryCookie"); if (cookie != null && cookie["access_token"] != null) { return cookie["access_token"]; } var authorizeRequest = new IdentityModel.Client.AuthorizeRequest( TripGallery.Constants.TripGallerySTSAuthorizationEndpoint); var state = HttpContext.Current.Request.Url.OriginalString; var url = authorizeRequest.CreateAuthorizeUrl("tripgalleryauthcode", "code", "gallerymanagement", TripGallery.Constants.TripGalleryMVCSTSCallback, state); HttpContext.Current.Response.Redirect(url); return null; }
private static string RequestAccessTokenAuthorizationCode() { // did we store the token before? var cookie = HttpContext.Current.Request.Cookies.Get("ClientMVCCookie.AuthCode"); if (cookie != null && cookie["access_token"] != null && !string.IsNullOrEmpty(cookie["access_token"])) { return(cookie["access_token"]); } // no token found - request one // we'll pass through the URI we want to return to as state var state = HttpContext.Current.Request.Url.OriginalString; var authorizeRequest = new IdentityModel.Client.AuthorizeRequest( IdentityConstants.AuthEndoint); var url = authorizeRequest.CreateAuthorizeUrl("mvc_client_auth_code", "code", "management", IdentityConstants.MVCAuthCodeCallback, state); HttpContext.Current.Response.Redirect(url); return(null); }
private void RequestToken(string scope, string responseType) { var request = new AuthorizeRequest(Constants.AuthorizeEndpoint); var startUrl = request.CreateAuthorizeUrl( clientId: "hybridclient", responseType: responseType, scope: scope, redirectUri: "oob://localhost/wpfclient", state: "random_state", nonce: "random_nonce"); _login.Show(); _login.Start(new Uri(startUrl), new Uri("oob://localhost/wpfclient")); }
public async static Task<AuthorizeResponse> DoImplicitFlowAsync( Uri endpoint, string clientId, string responseType, string scope, Uri redirectUri) { var request = new AuthorizeRequest(endpoint); var state = Guid.NewGuid().ToString("N"); var nonce = Guid.NewGuid().ToString("N"); var startUri = request.CreateAuthorizeUrl( clientId: clientId, responseType: responseType, scope: scope, redirectUri: redirectUri.AbsoluteUri, state: state, nonce: nonce, responseMode: "form_post"); try { var result = await WebAuthenticationBroker.AuthenticateAsync( WebAuthenticationOptions.UseHttpPost, new Uri(startUri)); if (result.ResponseStatus == WebAuthenticationStatus.Success) { return new AuthorizeResponse(result.ResponseData); } else if (result.ResponseStatus == WebAuthenticationStatus.UserCancel) { throw new Exception("User cancelled authentication"); } else if (result.ResponseStatus == WebAuthenticationStatus.ErrorHttp) { throw new Exception("HTTP Error returned by AuthenticateAsync() : " + result.ResponseErrorDetail.ToString()); } else { throw new Exception("Error returned by AuthenticateAsync() : " + result.ResponseStatus.ToString()); } } catch { // Bad Parameter, SSL/TLS Errors and Network Unavailable errors are to be handled here. throw; } }
public ActionResult Index(string scopes) { var state = Guid.NewGuid().ToString("N"); var nonce = Guid.NewGuid().ToString("N"); SetTempState(state, nonce); var request = new AuthorizeRequest(Constants.AuthorizeEndpoint); var url = request.CreateAuthorizeUrl( clientId: "codeclient", responseType: "code", scope: scopes, redirectUri: "https://localhost:44312/callback", state: state, nonce: nonce); return Redirect(url); }
private static string RequestTokenAuthorizationCode() { var cookie = HttpContext.Current.Request.Cookies.Get("ideal.auth"); if (cookie?["access_token"] != null) { return cookie["access_token"]; } var authorizeRequest = new AuthorizeRequest(IdealConstants.STSAuthorizationEndpoint); var state = HttpContext.Current.Request.Url.OriginalString; var url = authorizeRequest.CreateAuthorizeUrl(IdealConstants.ClientId, "code", "sampleApi", IdealConstants.ClientCallbackUrl, state); HttpContext.Current.Response.Redirect(url); return null; }
public IHttpActionResult ExternalLogin() { var state = Guid.NewGuid().ToString("N"); var nonce = Guid.NewGuid().ToString("N"); //SetTempState(state, nonce); var request = new AuthorizeRequest("https://localhost:44302/connect/authorize"); var url = request.CreateAuthorizeUrl( clientId: "AngularClient2", responseType: "code", scope: "Api", redirectUri: Url.Link("externalLoginCallBack", new {} ), state: state, nonce: nonce,acrValues:"idp:Facebook"); return Redirect(url); }
private string CreateUrl() { _nonce = CryptoRandom.CreateUniqueId(32); _verifier = CryptoRandom.CreateUniqueId(32); var challenge = _verifier.ToCodeChallenge(); var request = new AuthorizeRequest(_config.AuthorizationEndpoint); return request.CreateAuthorizeUrl( clientId: _settings.ClientId, responseType: "code id_token", scope: _settings.Scope, redirectUri: _settings.RedirectUri, nonce: _nonce, responseMode: OidcConstants.ResponseModes.FormPost, codeChallenge: challenge, codeChallengeMethod: OidcConstants.CodeChallengeMethods.Sha256); }
private static string RequestAccessTokenAuthorizationCode() { // did we store the token before? var cookie = HttpContext.Current.Request.Cookies.Get("TripGalleryCookie"); if (cookie != null && cookie["access_token"] != null) { return(cookie["access_token"]); } var authorizeRequest = new IdentityModel.Client.AuthorizeRequest( TripGallery.Constants.TripGallerySTSAuthorizationEndpoint); var state = HttpContext.Current.Request.Url.OriginalString; var url = authorizeRequest.CreateAuthorizeUrl("tripgalleryauthcode", "code", "gallerymanagement", TripGallery.Constants.TripGalleryMVCSTSCallback, state); HttpContext.Current.Response.Redirect(url); return(null); }
private async Task LoginUsingUsernameAndPasswordAsync() { const string responseType = "code id_token"; //implicit flow: "id_token token" // Space-separated list of scopes we want to receive var scopes = $"openid email profile offline_access {TimesheetConstants.ApiScope}"; var nonce = GenerateNonce(); // Unique token for the authorization request. try { var redirectUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri(); var request = new AuthorizeRequest(TimesheetConstants.AuthorizeEndpoint); var authUrl = request.CreateAuthorizeUrl(TimesheetConstants.ClientId, responseType, scopes, redirectUri.ToString(), nonce: nonce); var requestUri = new Uri(authUrl); var result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, requestUri, redirectUri); if (result.ResponseStatus == WebAuthenticationStatus.Success) { // Successful authentication, but we only have the ID token. var response = new AuthorizeResponse(result.ResponseData); // We need to ask for the access token and refresh tokens now. var tokenResponse = await GetAuthTokenAsync(response); // Store the tokens in the password vault ApiService.StoreTokenInVault(tokenResponse); // And finish the login process await FinishLoginAsync(tokenResponse); } } catch (Exception ex) { var dlg = new MessageDialog(ex.Message, "Error"); await dlg.ShowAsync(); } }
private void RequestToken(string scope, string responseType) { var request = new AuthorizeRequest(Constants.AuthorizeEndpoint); var startUrl = request.CreateAuthorizeUrl( clientId: "wpf.webview.client", responseType: responseType, responseMode:"form_post", scope: scope, redirectUri: "oob://localhost/wpf.webview.client", state: "random_state", nonce: "random_nonce" /**, loginHint: "alice", acrValues: "idp:Google b c" **/); _login.Show(); _login.Start(new Uri(startUrl), new Uri("oob://localhost/wpf.webview.client")); }
private async Task<string> CreateUrlAsync(AuthorizeResult result, string codeChallenge, object extraParameters) { var request = new AuthorizeRequest((await _options.GetEndpointsAsync()).Authorize); var url = request.CreateAuthorizeUrl( clientId: _options.ClientId, responseType: OidcConstants.ResponseTypes.CodeIdToken, scope: _options.Scope, redirectUri: result.RedirectUri, responseMode: _options.UseFormPost ? OidcConstants.ResponseModes.FormPost : null, nonce: result.Nonce, codeChallenge: codeChallenge, codeChallengeMethod: _options.UseProofKeys ? OidcConstants.CodeChallengeMethods.Sha256 : null, extra: extraParameters); return url; }