//public async Task<AccountConfiguration> CreateAccount() //{ // var type = _isAccessRestricted ? StorageType.DropboxRestricted : StorageType.Dropbox; // var clientId = _isAccessRestricted ? DropboxHelper.DropboxAppFolderOnlyClientId : DropboxHelper.DropboxFullAccessClientId; // var clientSecret = _isAccessRestricted ? DropboxHelper.DropboxAppFolderOnlyClientSecret : DropboxHelper.DropboxFullAccessClientSecret; // string[] scopes = // { // "account_info.read", // "files.metadata.write", // "files.metadata.read", // "files.content.write", // "files.content.read" // }; // var flow = new OidcFlow(type, clientId, clientSecret, scopes, 50001, 50005); // return await flow.AuthorizeOauth2Async("https://www.dropbox.com/oauth2/authorize", "https://api.dropboxapi.com/oauth2/token"); //} public async Task <AccountConfiguration> CreateAccount() { var f = new OidcWaitForm(); f.InitEx(_isAccessRestricted ? StorageType.DropboxRestricted : StorageType.Dropbox); f.Show(); var clientId = _isAccessRestricted ? DropboxHelper.DropboxAppFolderOnlyClientId : DropboxHelper.DropboxFullAccessClientId; var clientSecret = _isAccessRestricted ? DropboxHelper.DropboxAppFolderOnlyClientSecret : DropboxHelper.DropboxFullAccessClientSecret; string[] scopes = { "account_info.read", "files.metadata.write", "files.metadata.read", "files.content.write", "files.content.read" }; var browser = new OidcSystemBrowser(50001, 50005); var redirectUri = browser.RedirectUri; var state = Guid.NewGuid().ToString("N"); var codeVerifier = db.DropboxOAuth2Helper.GeneratePKCECodeVerifier(); var codeChallenge = db.DropboxOAuth2Helper.GeneratePKCECodeChallenge(codeVerifier); var uri = db.DropboxOAuth2Helper.GetAuthorizeUri(db.OAuthResponseType.Code, clientId, redirectUri, state, false, false, null, false, db.TokenAccessType.Offline, scopes, db.IncludeGrantedScopes.None, codeChallenge); var query = await browser.GetQueryStringAsync(uri.ToString(), f.CancellationToken); var resultState = query["state"]; if (state != resultState) { throw new Exception("MiM-Attack?"); } var code = query["code"]; var response = await db.DropboxOAuth2Helper.ProcessCodeFlowAsync(code, clientId, null, redirectUri, null, codeVerifier); var api = DropboxHelper.GetApi(response.AccessToken); var owner = await api.Users.GetCurrentAccountAsync(); var account = new AccountConfiguration() { Id = owner.AccountId, Name = owner.Name.DisplayName, Type = _isAccessRestricted ? StorageType.DropboxRestricted : StorageType.Dropbox, Secret = response.RefreshToken, }; f.Close(); return(account); }
public async Task <AccountConfiguration> CreateAccount() { var isOk = OAuth2Flow.TryAuthenticate(this); if (!isOk) { return(null); } var api = DropboxHelper.GetApi(_oauthResponse.AccessToken); var owner = await api.Users.GetCurrentAccountAsync(); var account = new AccountConfiguration() { Id = owner.AccountId, Name = owner.Name.DisplayName, Type = _isAccessRestricted ? StorageType.DropboxRestricted : StorageType.Dropbox, Secret = _oauthResponse.AccessToken, }; return(account); }