@manhng

Welcome to my blog!

OAuth2 + OpenID Connect (in English)

October 12, 2019 17:22

Authentication on the Web (Sessions, Cookies, JWT, localStorage, and more) (edit)

https://www.youtube.com/watch?v=2PPSXonhIck

OAuth 2.0 and OpenID Connect (in plain English)

https://www.youtube.com/watch?v=996OiexHze0

OAuth 2.0 terminology

  • Resource owner
  • Client
  • Authorization server
  • Resource server
  • Authorization grant
  • Redirect URI
  • Access token

 

Test OAuth 2.0 requests and debug responses.

https://oauthdebugger.com/

Decode, verify and generate JWT

https://jwt.io/

OpenID Connect

Test OpenID Connect requests and debug responses.

https://oidcdebugger.com/

https://www.websiterank.co.uk/vi/domain/manhng.com/

Microsoft

https://devblogs.microsoft.com/aspnet/2019/10/

Generate Code using T4 Template

https://devblogs.microsoft.com/aspnet/how-to-customize-the-generated-files-from-the-new-scaffolded-item-dialog/

Identity Server 4

OpenID Connect and OAuth 2.0 Framework for ASP.NET Core

https://github.com/IdentityServer

OpenID Connect and OAuth 2.0 Framework for ASP.NET Core

Additional resources

JWT

https://docs.microsoft.com/en-us/dotnet/architecture/microservices/secure-net-microservices-web-applications/

https://abelsquidhead.com/index.php/2017/12/18/using-tokens-and-cookies-for-authorization-for-asp-net-core-2-0/

https://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/

https://salslab.com/a/jwt-authentication-and-authorisation-in-asp-net-core-web-api

https://www.blinkingcaret.com/2018/07/18/secure-an-asp-net-core-web-api-using-cookies/

https://garywoodfine.com/asp-net-core-2-2-jwt-authentication-tutorial/

http://www.dotnetpedia.com/nityaprakash/Blog/2017/Oct/1029/JWT-Token-based-Authentication-in-ASP-Net-Core-Web-API

https://www.meziantou.net/jwt-authentication-with-asp-net-core.htm

https://fullstackmark.com/post/13/jwt-authentication-with-aspnet-core-2-web-api-angular-5-net-core-identity-and-facebook-login

https://amanagrawal.blog/2017/09/18/jwt-token-authentication-with-cookies-in-asp-net-core/

https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-html5-web-storage

http://www.binaryintellect.net/articles/1fdc8b3f-06a1-4f36-8c0b-7852bf850f52.aspx/

https://www.red-gate.com/simple-talk/dotnet/net-development/using-auth-cookies-in-asp-net-core/

https://www.c-sharpcorner.com/blogs/jwt-based-tokenisation-via-net-core

JWT in ASP.NET 3.0

https://jasonwatmore.com/post/2019/10/11/aspnet-core-3-jwt-authentication-tutorial-with-example-api

https://dotnetdetail.net/asp-net-core-3-0-web-api-token-based-authentication-example-using-jwt-in-vs2019/

https://www.codeproject.com/Articles/5160941/ASP-NET-CORE-Token-Authentication-and-Authorizatio

https://www.c-sharp.vn/dot-net-core/dot-net-core-bearer-token-with-jwt-e477ff

BASIC JAVASCRIPT PROJECTS

https://www.youtube.com/watch?v=Kp3HGwlXwCk

ASP.NET Core 3.0 + EF Core 3.0 + Web API + Swagger + JWT

October 7, 2019 21:29

ASP.NET Core 3.0 + EF Core 3.0 + Web API + Swagger + JWT

Dependencies

EF Core 3.0

 

 

Swaager

Authorization: Bearer eyJhb...Do

cUrl (link download)

curl -X POST "https://localhost:5001/api/v1/identity/register" -H "accept: */*" -H "Content-Type: application/json" -d "{\"email\":\"test@abc.com\",\"password\":\"Abc@123!\"}" -k

curl -X POST "https://localhost:5001/api/v1/identity/login" -H "accept: */*" -H "Content-Type: application/json" -d "{\"email\":\"test@abc.com\",\"password\":\"Abc@123!\"}" -k

curl -X POST "https://localhost:5001/api/v1/posts" -H "accept: */*" -H "Authorization: Bearer eyJhb...Do" -H "Content-Type: application/json" -d "{\"name\":\"ASP.NET Core + EF Core + WebAPI\",\"tags\":[\"ASP.NET Core\"]}" -k

Source code (link download)

Git

October 5, 2017 17:50

Git Usage (edit)

Tổng hợp 35 lệnh GIT cơ bản - Deft Blog (shareprogramming.net)

Top 35 Git Commands With Examples - DZone DevOps

Giải thích chi tiết những câu lệnh thường dùng trong Git - Thau Nguyen

Git Clone

Git Clone cho phép các lập trình viên copy một Remote Repo về Local, ngoài ra có thể ứng dụng trong các trường hợp sau:

  • Copy một Repo từ máy Remote về Local
  • Copy một Repo từ thư mục này sang một thư mục khác
  • Copy một Repo từ một Url (https) ví dụ GitHub
git clone --recursive https://github.com/garymcleanhall/AdaptiveCode.git
git clone --recursive https://github.com/AdaptiveCode/AdaptiveCode.git

Khi bạn muốn xem thay đổi trên nhánh hiện tại

git reflog

With git reflog check which commit is one prior the merge (git reflog will be a better option than git log). Then you can reset it using:

git reset --hard commit_sha

There's also another way:

git reset --hard HEAD~1

It will get you back 1 commit.

Be aware that any modified and uncommitted/unstashed files will be reset to their unmodified state. To keep them either stash changes away or see --merge option below.

Khi bạn muốn bỏ tất cả thay đổi của lệnh git merge

git reset --hard HEAD~1

git reset --merge HEAD~1

Khi bạn muốn bỏ tất cả thay đổi

git checkout -f

git clean -d -f -f

git reset --hard HEAD

Khi bạn gặp tình huống phải lấy lại toàn bộ source của một branch theo một commit xác định

Lý do: Để kiểm tra những thay đổi bạn đã làm ở thời điểm hiện tại so với thời điểm commit xác định ở trên

git checkout -b <new-branch-name> <commit-id-sha>

git checkout -B <new-branch-name> <commit-id-sha>

bitbucket - how to checkout a specific commit from git - Stack Overflow

git checkout 9ce920d

git checkout -B new_branch

git reset 9ce920d

Add Git Ignore to existing Repository | FreeCode Spot

Trong quá trình làm việc, chúng ta có thể rơi vào trường hợp khi đang thực hiện một công việc dang dở nhưng phải tạm dừng và chuyển qua một nhánh mới để thực hiện tiến trình khác. Nếu chúng ta chỉ muốn lưu lại các thay đổi mà chưa commit thì git stash sẽ giúp bạn.

Bạn đang có vài thay đổi và muốn chuyển qua branch khác, bạn chỉ cần chạy git stash hoặc git stash save.

Lúc này bạn đã có thể chuyển sang branch mới.

Để xem lại cách thay đổi đã được lưu lại, bạn dùng lệnh: git stash list.

Apply thay đổi: git stash apply.

Xoá toàn bộ: git stash clear.

Một số định nghĩa thường gặp khi sử dụng Git. (viblo.asia)

Có 2 lợi ích cơ bản và quan trọng của VCS là:

  • Lưu lại toàn bộ lịch sử thay đổi của phiên bản. Giúp lập trình viên theo dõi và khôi phục dễ dàng sau này.
  • Việc chia sẻ code có thể public cho bất kỳ ai, và cũng có thể để chế độ private cho những người có thẩm quyền được truy cập và tải code về. Giúp việc chia sẻ đơn và dễ dàng với Git.
  • Git hỗ trợ làm việc offline.
  • Hoàn toàn miễn phí.

[Git Là Gì] - Các lệnh cơ bản khi làm việc với Git | Vietnix

Git Cheet Sheets

Bạn không thể nào nhớ được hết các lệnh, lúc này bạn nên sử dụng các Git Cheet Sheets để dễ dàng tìm được lệnh Git bạn cần:

1) Tìm kiếm tên người dùng

git shortlog -s --author="John"

git log --pretty="%an"

2) Hiển thị danh sách tất cả người dùng

git shortlog -sn --all

3) Hiển thị log

git log --pretty=oneline

git log --oneline

git log --oneline --author="John"

git log --author="John"

git log --author="John" --oneline

git log:

  • 1afd158ebdd8c2e3282d8f90fda33775acc8477c
  • 122f3796d1420471aa9f7f30c6db64c5a3f07114
  • fd8c0be685c75b14ebe53e522408c23baa8bbbc4

git show 1afd158ebdd8c2e3282d8f90fda33775acc8477c

git show --name-only 1afd158ebdd8c2e3282d8f90fda33775acc8477c

git log --name-only 1afd158ebdd8c2e3282d8f90fda33775acc8477c

git diff --name-only 1afd158ebdd8c2e3282d8f90fda33775acc8477c..HEAD

4) How do I list all of the files in a commit?

git diff-tree --no-commit-id --name-only -r bd61ad98
git show --pretty="" --name-only bd61ad98
git log -p
git show da475798411a3e2769219b4a7655b6821c4d1901

5) How can I list all commits that changed a specific file?

git log --follow -- filename

6) Hiển thị danh sách tệp thay đổi

git log --author="John" --oneline

  • 44669cc
  • 1afd158
  • ...

git show --name-only 44669cc

  • test.cs
  • text.txt

git-tips/tips: Most commonly used git tips and tricks. (github.com) (HAY HAY HAY HAY HAY)

Syncing a Fork of a GitHub Repository with Upstream | Blog (ardalis.com) (HAY HAY HAY HAY HAY)

Basic Syntax | Markdown Guide

Advanced Git - @manhng (git)

Git Common Line Interface - @manhng (git log, git show, gitk --follow)

Git Commands - @manhng (git)

Git - @manhng (git)

7 Git Commands That Saved My Life Atleast Once | by Lucas Tagliani Aguiar | Aug, 2021 | Better Programming

13 Git Commands Every Developer Must Know (zepel.io)

15 Git Hacks to Save your Life as a Developer | by GitShip | Medium

Life-saving git commands - DEV Community (HAY HAY HAY)

4 Useful Git Commands That Save Time | Codica (HAY HAY HAY)

List of life saving git commands – Tugrul ASLAN

Git stash

git stash save

git stash list

git stash apply

Show all developers and comments of the last N commits

git shortlog -sne

git shortlog --summary --numbered --email

git log

git log -1

git log -5

git show --summary

git show --summary -1

git show --summary -5

git log -n 5 --author=ducnn

git log --oneline -n 5 --author=ducnn

Showing all commits

git rev-list --remotes

git rev-list --all --remotes --pretty

git rev-list --all --pretty=oneline

git log --name-status --oneline

git log origin/master..HEAD

git diff --name-only <SHA, tag start> <SHA, tag end>

git diff --name-only HEAD HEAD~3

git diff origin/master..HEAD

Showing committed files that your will push to the remote

git diff --stat --patch origin dev

Chuyển toàn bộ thay đổi sang nhánh mới

git switch -c <new-branch>
git checkout -b <new-branch>
git add <files>
git commit -m "<Brief description of this commit>"

Bỏ thay đổi đang có

git checkout -f

git clean -d -f -f

git reset --hard
git reset --hard HEAD

Bỏ thay đổi

1) Don't remove staged files

git reset --soft HEAD^

2) Remove staged files

git reset HEAD^

If you want to undo commit and lose all the changes, you can use

git reset --hard HEAD^

Xóa nhánh (delete branch)

// delete branch locally
git branch -d localBranchName

// delete branch remotely
git push origin --delete remoteBranchName

Clone chỉ một branch

git clone git@gitlab.company.vn:adc/company-api.git --branch dev --single-branch company-api

Git - @manhng

Advanced Git - @manhng

Cách phân nhánh và chia việc trong nhóm với Git – Ehkoo

Nhàn hơn cùng git stash! (viblo.asia)

Kết luận

Chúng ta có thể tóm tắt bài này lại như sau:

  • Dự án được chia thành nhiều nhánh, bao gồm master, dev và có thể có staging
  • Các nhánh tính năng được chia ra từ dev, phát triển độc lập, được rebase trước khi merge lại vào dev
  • Rebase có thể thay đổi một chút history, hoặc squash lại thành một commit duy nhất
  • Merge có thể là fast-forward hoặc non-fast-forward
  • dev sẽ được merge vào master mỗi khi triển khai. Trường hợp có staging, dev sẽ được merge vào staging, và staging sẽ được merge vào master.
  • Các nhánh hotfix sẽ được chia ra từ master, sau đó merge --no-ff vào master  dev

Dĩ nhiên bài viết này chỉ mang tính tham khảo, vì mỗi team mỗi công ty sẽ có những cách làm riêng.

Khi bạn muốn bỏ tất cả thay đổi

git checkout -f

git clean -d -f -f

git reset --hard HEAD

Khi bạn gặp tình huống phải lấy lại toàn bộ source của một branch theo một commit xác định

Lý do: Để kiểm tra những thay đổi bạn đã làm ở thời điểm hiện tại so với thời điểm commit xác định ở trên

git checkout -b <new-branch-name> <commit-id-sha>

git checkout -B <new-branch-name> <commit-id-sha>

bitbucket - how to checkout a specific commit from git - Stack Overflow

git checkout 9ce920d
git checkout -B new_branch
git reset 9ce920d

Git - Học nghiêm túc một lần (Phần 1)

https://viblo.asia/p/git-hoc-nghiem-tuc-mot-lan-phan-1-OeVKBo6JZkW

Git - Học nghiêm túc một lần (Phần 2)

https://giaphiep.com/blog/git-hoc-nghiem-tuc-mot-lan-phan-2-25505

Git - Những câu lệnh hữu dụng

https://viblo.asia/p/tap-hop-nhung-cau-lenh-git-huu-dung-dWrvwWr2vw38

Git - Những câu lệnh cơ bản

https://jusfunny.wordpress.com/2016/11/09/cac-lenh-git-co-ban-ma-toi-hay-dung/

Hủy lệnh merge

git merge --abort

git reset --hard HEAD

Các câu lệnh thường dùng

git checkout master
git pull origin master
git merge test
git push origin master

Getting Started

http://rogerdudler.github.io/git-guide/

Chuyển sang nhánh develop và xóa những thay đổi ở nhánh hiện tại

Giả sử bạn đang ở nhánh my_branch và muốn chuyển sang nhánh develop đồng hời không muốn giữ thay đổi ở nhánh hiện tại

git checkout -f develop

Undo a Git merge | Reverting a Git Merge

git reset --hard HEAD~1
git reset --hard ORIG_HEAD
git revert HEAD

Remove file

Use git rm:

git rm file1.txt
git commit -m "remove file1.txt"

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt
git commit -m "remove file1.txt"

And to push changes to remote repo

git push origin branch_name

Remove directory from git and local

You could checkout 'master' with both directories;

git rm -r one-of-the-directories
git commit -m "Remove duplicated directory"
git push origin <your-git-branch> (typically 'master', but not always)

Remove directory from git but NOT local

As mentioned in the comments, what you usually want to do is remove this directory from git but not delete it entirely from the filesystem (local)

In that case use:

git rm -r --cached myFolder

Getting Started (continue)

git init

git config --list

git config --global core.editor emacs

git config --global merge.tool vimdiff

git config user.name
git config user.email

git config user.name "John Doe"
git config user.email johndoe@example.com

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

git clone "https://manhnv@git.company.vn/crm/dev.git"

Determine the URL that a local git repository was originally cloned from

git config --get remote.origin.url
git remote show origin

git add -all
git commit -am "<message>"
git push origin master

git reset --hard

git clean -f

git clean -n
Would remove untracked_file

git clean -f
Removing untracked_file

git clean -dn
Would remove untracked_dir/

git clean -df
Removing untracked_dir/

Tham khảohttp://techkids.vn/blog/cac-cau-lenh-git-khong-khong-biet/ 

git checkout develop

git merge ONGAME-134

comment "ONGAME-134…

press I for INSERT

press ESC for exit INSERT

:qw

ghi và thoát

:q!

lưu lại nội dung như cũ

press ENTER

1/ Một số lệnh git sử dụng với Git Bash

Bạn commit gặp lỗi và muốn xem chuyện gì đang xảy ra?

git log --oneline -10 

git reset --soft c66f836

git status

git log --oneline -10

Bạn muốn xem lệnh commit gần nhất?

git show

Bạn muốn xem có bao nhiêu branch và đang ở branch nào?

git branch

Bạn muốn merge code từ nhánh develop vào nhánh master?

git checkout master

git merge develop

git status

git push origin master

2/ Một số lỗi thường gặp với Git

Gặp lỗi git không commit được vì có nhiều tài khoản git trên cùng 1 máy

Cmd > control userpasswords2

Advanced > Manage Passwords > Web Credentials > Remove all credentials related with git, github...

Categories

Recent posts