private void UpdateAuthenticationManager() { // Define the server information for ArcGIS Online ServerInfo portalServerInfo = new ServerInfo { // ArcGIS Online URI ServerUri = new Uri(ArcGISOnlineUrl), // Type of token authentication to use TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit }; // Define the OAuth information OAuthClientInfo oAuthInfo = new OAuthClientInfo { ClientId = AppClientId, RedirectUri = new Uri(_oAuthRedirectUrl) }; portalServerInfo.OAuthClientInfo = oAuthInfo; // Get a reference to the (singleton) AuthenticationManager for the app AuthenticationManager thisAuthenticationManager = AuthenticationManager.Current; // Register the ArcGIS Online server information with the AuthenticationManager thisAuthenticationManager.RegisterServer(portalServerInfo); // Create a new ChallengeHandler that uses a method in this class to challenge for credentials thisAuthenticationManager.ChallengeHandler = new ChallengeHandler(CreateCredentialAsync); // Set the OAuthAuthorizeHandler component (this class) for Android or iOS platforms #if __ANDROID__ || __IOS__ thisAuthenticationManager.OAuthAuthorizeHandler = this; #endif }
private void UpdateAuthenticationManager() { // Define the server information for ArcGIS Online ServerInfo portalServerInfo = new ServerInfo(); // ArcGIS Online URI portalServerInfo.ServerUri = new Uri(ArcGISOnlineUrl); // Type of token authentication to use portalServerInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit; // Define the OAuth information OAuthClientInfo oAuthInfo = new OAuthClientInfo { ClientId = AppClientId, RedirectUri = new Uri(OAuthRedirectUrl) }; portalServerInfo.OAuthClientInfo = oAuthInfo; // Get a reference to the (singleton) AuthenticationManager for the app AuthenticationManager thisAuthenticationManager = AuthenticationManager.Current; // Register the ArcGIS Online server information with the AuthenticationManager thisAuthenticationManager.RegisterServer(portalServerInfo); // Create a new ChallengeHandler that uses a method in this class to challenge for credentials thisAuthenticationManager.ChallengeHandler = new ChallengeHandler(CreateCredentialAsync); }
public void OnGetRequestCode() { const string OAUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth"; if (System.IO.File.Exists(TOKEN_FILE)) { return; } var user = OAuthClientInfo.LoadClientSecretsInfo(); var redirectUri = user.RedirectUris.FirstOrDefault(); if (redirectUri == null) { throw new SystemException("Missing redirect url in user credentials"); } var queryParams = new Dictionary <string, string> { { "client_id", user.ClientId }, { "scope", YouTubeService.Scope.YoutubeUpload }, { "response_type", "code" }, { "redirect_uri", redirectUri }, { "access_type", "offline" }, { "prompt", "consent" } }; var newUrl = QueryHelpers.AddQueryString(OAUTH_URL, queryParams); base.Response.Redirect(newUrl); }
private async void ExchangeCodeForTokenAsync(string code) { var user = OAuthClientInfo.LoadClientSecretsInfo(); var redirectUri = user.RedirectUris.FirstOrDefault(); if (string.IsNullOrWhiteSpace(redirectUri)) { throw new SystemException("Missing redirect url in user credentials"); } var payload = new Dictionary <string, string> { { "code", code }, { "client_id", user.ClientId }, { "client_secret", user.ClientSecret }, { "redirect_uri", redirectUri }, { "grant_type", "authorization_code" } }; var content = new FormUrlEncodedContent(payload); var client = _clientFactory.CreateClient(); var response = await client.PostAsync(user.TokenUri, content); response.EnsureSuccessStatusCode(); if (response.IsSuccessStatusCode) { var jsonString = await response.Content.ReadAsStringAsync(); string fileName = System.IO.Path.Combine(_hostingEnvironment.ContentRootPath, TOKEN_FILE); await System.IO.File.WriteAllTextAsync(fileName, jsonString, Encoding.UTF8); } }
private void UpdateAuthenticationManager() { // OAuth client info OAuthClientInfo oauthInfo = new OAuthClientInfo { ClientId = OAuthPage.AppClientId, RedirectUri = new Uri(OAuthPage.OAuthRedirectUrl) }; // If a client secret has been included, add it if (!string.IsNullOrEmpty(OAuthPage.ClientSecret)) { oauthInfo.ClientSecret = OAuthPage.ClientSecret; } // Register the server information (and OAuth info) with the AuthenticationManager ServerInfo portalServerInfo = new ServerInfo { ServerUri = new Uri(OAuthPage.PortalUrl), OAuthClientInfo = oauthInfo, }; // Specify OAuthAuthorizationCode if a valid client secret has been specified (need a refresh token, e.g.) if (!string.IsNullOrEmpty(OAuthPage.ClientSecret)) { portalServerInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode; } else { // Otherwise, use OAuthImplicit portalServerInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit; } // Get a reference to the (singleton) AuthenticationManager for the app AuthenticationManager thisAuthenticationManager = AuthenticationManager.Current; // Register the server information thisAuthenticationManager.RegisterServer(portalServerInfo); // Assign the method that AuthenticationManager will call to challenge for secured resources thisAuthenticationManager.ChallengeHandler = new ChallengeHandler(CreateCredentialAsync); // Set the OAuth authorization handler to this class (Implements IOAuthAuthorize interface) thisAuthenticationManager.OAuthAuthorizeHandler = this; }
private void UpdateAuthenticationManager() { // OAuth client info OAuthClientInfo oauthInfo = new OAuthClientInfo { ClientId = AppClientId, RedirectUri = new Uri(OAuthRedirectUrl) }; // If a client secret has been included, add it if (!string.IsNullOrEmpty(ClientSecret)) { oauthInfo.ClientSecret = ClientSecret; } // Register the server information (and OAuth info) with the AuthenticationManager ServerInfo portalServerInfo = new ServerInfo { ServerUri = new Uri(PortalUrl), OAuthClientInfo = oauthInfo, }; // Specify OAuthAuthorizationCode if a valid client secret has been specified (need a refresh token, e.g.) if (!string.IsNullOrEmpty(ClientSecret)) { portalServerInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode; } else { // Otherwise, use OAuthImplicit portalServerInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit; } // Get a reference to the (singleton) AuthenticationManager for the app AuthenticationManager thisAuthenticationManager = AuthenticationManager.Current; // Register the server information thisAuthenticationManager.RegisterServer(portalServerInfo); // Assign the method that AuthenticationManager will call to challenge for secured resources thisAuthenticationManager.ChallengeHandler = new ChallengeHandler(CreateCredentialAsync); // Set the OAuth authorization handler to this class (Implements IOAuthAuthorize interface) thisAuthenticationManager.OAuthAuthorizeHandler = this; }
public async void OnPostAsync() { var video = GetVideoData(VideoUpload.Title, VideoUpload.Description); var user = OAuthClientInfo.LoadClientSecretsInfo(); if (!System.IO.File.Exists(TOKEN_FILE)) { throw new SystemException("missing access token file. Request for authorization code before uploading a video"); } var tokenResponse = await FetchToken(user); var youTubeService = FetchYouTubeService(tokenResponse, user.ClientId, user.ClientSecret); using (var fileStream = new FileStream(_tempFilePath, FileMode.Open)) { var videosInsertRequest = youTubeService.Videos.Insert(video, "snippet, status", fileStream, "video/*"); videosInsertRequest.ProgressChanged += VideoUploadProgressChanged; videosInsertRequest.ResponseReceived += VideoUploadResponseReceived; await videosInsertRequest.UploadAsync(); } }
public void RegisterConfigurationObject(OAuthClientInfo oAuthData, YammerBaseUris yammerUris) { Container.Instance<IClientConfiguration>(new ClientConfiguration(oAuthData, new ProductInfoHeaderValue("Yammer_Activites", AppVersion.Version.ToString()), yammerUris, DefaultTimeoutSeconds)); }
private void UpdateAuthenticationManager() { // Define the server information for ArcGIS Online ServerInfo portalServerInfo = new ServerInfo(); // ArcGIS Online URI portalServerInfo.ServerUri = new Uri(ArcGISOnlineUrl); // Type of token authentication to use portalServerInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit; // Define the OAuth information OAuthClientInfo oAuthInfo = new OAuthClientInfo { ClientId = AppClientId, RedirectUri = new Uri(OAuthRedirectUrl) }; portalServerInfo.OAuthClientInfo = oAuthInfo; // Get a reference to the (singleton) AuthenticationManager for the app AuthenticationManager thisAuthenticationManager = AuthenticationManager.Current; // Register the ArcGIS Online server information with the AuthenticationManager thisAuthenticationManager.RegisterServer(portalServerInfo); // Use the OAuthAuthorize class in this project to create a new web view to show the login UI thisAuthenticationManager.OAuthAuthorizeHandler = new OAuthAuthorize(); // Create a new ChallengeHandler that uses a method in this class to challenge for credentials thisAuthenticationManager.ChallengeHandler = new ChallengeHandler(CreateCredentialAsync); }