How to access bitbucket using app password - bitbucket

I have created an app password as explained here
But now, how do I access the repository using this app password?What will be the url?Can someone direct me to a page showing an example please?
The below is a code for github. How do I do it for bitbucket?
var githubToken = "[token]";
var url = "https://github.com/[username]/[repository]/archive/[sha1|tag].zip";
var path = #"[local path]";
using (var client = new System.Net.Http.HttpClient())
{
var credentials = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:", githubToken);
credentials = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(credentials));
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials);
var contents = client.GetByteArrayAsync(url).Result;
System.IO.File.WriteAllBytes(path, contents);
}
Update
Go to Personal Settings and then App Passwords as shown below.

Since the question was "how do I access the repository" - maybe this is useful for somebody:
You can also use a Bitbucket "App Password" to use Git over HTTPS.
git clone https://USERNAME:APP_PASSWORD#bitbucket.org/OWNER/REPO.git
(Or, if you want to avoid storing the password in plaintext:
Omit :APP_PASSWORD in the URL above, and just provide the App Password when prompted by Git.)
This may be useful for CI (although Git over SSH might be better).

You can perform this request as follows:
curl -u "walery2iq:<appPassword>" "https://api.bitbucket.org/2.0/repositories/[yourRepo]"
Important thing here - use your username, not e-mail address.
Important because for login on bitbucket itself you are using e-mail and not username :D
You can find your username here:
Settings -> Account settings -> Username
See picture.

You need to create your "app password" on bitbucket console. Under your Avatar ->Personal Settings ->Access Management ->App Password. Create app password and note it down.
Once done, open your git bash and set the remote origin using -
git remote set-url origin https://<Your_Account_Name>:<App_Password>#bitbucket.org/<Your_Account_Name>/<Repo_Name>.git

If you have a 2-step verification I was able to clone but not to make a push. This worked for me using git instead of curl:
git push https://<username>:<GENERATED-APP-PASS>#bitbucket.org/<username>/<repo>.git
Generate an app password at https://bitbucket.org/account/admin/app-passwords

git remote set-url origin https://[app-label]:[app-password]#bitbucket.org/[your-repo].git

Git uses libcurl under the hood so one might keep password in ~/.netrc file:
machine bitbucket.org login USER password PAZZ
and avoid leaking password to shell history:
git clone https://$USER#bitbucket.org/$WORKSPACE/$REPO.git

This worked for me, check use credential helper from git settings.
That is, preferences-> version control-> To git -> use credential helper

Related

How to push to bitbucket using jgit

I am trying to push code to bitbucket using jgit. Clone is working with ssh, but to push - I need to set credentials and I am getting "not authorized " error. I tried username, password, ("Private-token", access-token) and app password also
While pushing after a successful clone, ii am getting "origin not found" error also
Please advise
"Not authorized" might mean that you don't have permissions to push to the specified branch. E.g. there might be a policy to not allow to push directly into main branch. Usually developers should push to feature branches and then submit pull requests to ask for code review before merging to the main branch.
As for "origin not found" please check the remotes. The default name for remote repository is origin, but you might have it differently. Also it might be an issue with the command parameters. Please provide more details.

App Passwords and BitBucket / TortoiseGit / Pageant

I had an email Atlassian today saying I must start to use App Password for linking with BitBucket.
I use:
TortoiseGit
Pageant
Up until now I have always input a passphrase each morning I do my first commit and there after I get no prompts.
I have followed the instructions to create an App Password but I do not know how to change TortoiseGit / Pageant to use this new App Password.
You only need to use an AppPassword when you're not using an SSH key for authentication.
IIRC the AppPassword can just be entered as a password when you use an HTTPS-based remote.

SourceTree, Error Logon failed, use ctrl+c to cancel basic credential prompt

I'm getting below error while cloning a repo through Sourcetree.
I'm able to login directly through bitbucket.org but not through Sourcetree. Let me know how this issue needs to be fixed.
SourceTree version: 3.3.9
TIA
Let's try this:
Tools -> Options -> Authentication
Click "Edit" on Your Account
Click "Refresh OAuth Token"
It works for me :)
I found out that the reason why SourceTree cannot authorize our GitHub account is that source tree is using the old git version so that it doesn't authorize our account through web but through its own application which is not permitted by Git.
Git Notification
Solution:
First of all, you must know where your SourceTree stores your local datas (which is also the local git). You go to Tools > Options. Choose Git tab, and then choose Embeded in Git version which will tell you the path to their local datas. Mine is "C:\Users\as\AppData\Local\Atlassian".
Git Local path
And then you need to delete all the folder in the Atlassian and then uninstall SourceTree.
After all, you install new version of Git from this: https://gitforwindows.org/ and install new SourceTree from this: https://www.sourcetreeapp.com/
And then you just need to open your repository from the Add button, and try to push again.
SourceTree
They will appear the web-authorization for you to sign in. And after all that, it works.
Git Authentication
Authenticate with OAuth instead of Basic.
Tools/Options/Authentication, delete your github account, add again. Works for me.
Tools> Options> Authentication> Edit already existing account - Enter password and save again. This might refresh your password in your SourceTree
This is still relevant!
I solve it by updating SourceeTree.
Remove Sourcetree from PC
Download the new version from the official site: click
After open, on the top right corner press the yellow flag to update, then click "restart".
Go to Tools => Settings => GIT => Update Embedded.
For version 3.4.0 I have Embedded v2.29.2.
Then press Fetch, for example. Select "Use no helper" in a popup window. Also, check "don't ask again". Enter email/login and password into the login popup.
Success for me :)
I had this exact issue. I opened the project in Visual Studio 2019 and attempted the same request as before. This prompted me for the same username and password, but also allowed me to authorize using the website. I selected this and was able to go back into SourceTree and continue the clone.

Unable to Authenticate my Bitbucket server account with Sourcetree / How to register in source tree with Bitbucket Server credentials

I have a Bitbucket repository, which I'm able to logging in web browser with my credentials, Now I want to checkout it in Sourcetree, So I've installed Sourcetree 2.6.10, It requires authentication to Bitbucket server with Root URL & Username to continue, I'm providing input in below format...
Root URL : https://bitbucket.xxxxxxx.com
Username : xxxxxx.xxxxxx
The error i'm getting is...
Failed to check login for user [xxxxx.xxxxxx]. You do not have permission to access URL ‘https://bitbucket.xxxxxxxxx.com/rest/api/1.0/users/xxxxxx.xxxxxx’ please check the user credentials associated with this account. The request returned with status code ‘Unauthorized’.
Any help would be appreciated, thanks !
To fix:
1-go to source tree window, clicked remote
2-little gear icon, clicked "settings"
3-double clicked on Bitbucket server, changed protocol from default HTTPS to SSH
To Perforce, Now, I m sharing another solution whether if the user prefers, BitBucket Cloud intergrated with SourceTree,(facing the above stated issue),
Since one of the steps of the upgrade process was to input your Atlassian account password, you should now have a password set (in addition to being able to use Google). You should be able to use your Bitbucket username and Atlassian account password to authenticate SourceTree.
If you need to reset your Atlassian account password, you can do so here: https://id.atlassian.com/login/resetpassword
Source : https://community.atlassian.com/t5/Bitbucket-questions/Cannot-login-with-Bitbucket-in-SourceTree-after-linking-with/qaq-p/145231
I had a similar problem trying to register Sourcetree the first time I opened it, using my company's Bitbucket Server URL. Turns out I just needed to include https:// at the beginning of the URL.
Drop everything after ".com" and log in there.
e.g. log into
https://bitbucket.xxxxxxx.com
not
‘https://bitbucket.xxxxxxxxx.com/rest/api/1.0/users/xxxxxx.xxxxxx’
see also
https://jira.atlassian.com/browse/SRCTREEWIN-8743

Unexpected HTTP status code: 403 (-1) Xcode

I have this error when I push my code to Github repository by Xcode
Before answering the question you must know:
Although everyone can make a pull request, you can't just push to a repository. ِِYou need permission.
So this happened for me because in my Xcode, I was pushing to a remote that belonged to one of the other members ie I didn't have permission to push to.
You have two options:
Ask for permission from the owner of that remote repo/fork and have them include into one of its collaborators
Or Simply push to a repo that you have permission like your own repo,
using the dropdown menu encircled below (and perhaps then make a pull request from there to that branch you wanted to push to)
I usually run into this issue when I checkout directly from a remote branch ie I do something like:
git checkout -b localFromUpstream upstream/someBranch
And then when I commit, Xcode assumes that I want to push back to upstream/someBranch. But I don't permission to push to upstream/someBranch.
HTTP code 403 means forbidden, so it is most probably incorrect credentials. So double check your username and password etc.
https://en.wikipedia.org/wiki/HTTP_403
Even you can make a pull request, but can't just push to a repository. ِِYou need permission.
Inviting collaborators to a personal repository
Ask for the username of the person you're inviting as a collaborator. If they don't have a username yet, they can sign up for GitHub.
On GitHub, navigate to the main page of the repository.
Under your repository name, click Settings.
In the left sidebar, click Collaborators.
Under "Collaborators", start typing the collaborator's username.
Select the collaborator's username from the drop-down menu.
Click Add collaborator.
The user will receive an email inviting them to the repository. Once they accept your invitation, they will have collaborator access to your repository.

Resources