首页 > 解决方案 > (如何)我可以使用 Gitlab.com 对我的 Angular 应用程序进行身份验证吗?

问题描述

我想看看如何通过 Gitlab.com 进行身份验证的用户可以通过我们的 Angular 网站进行身份验证。
我已经看到了一些使用https://gitlab.com/oauth/applications/
的建议 我们使用 gitlab.com 作为我们的 CI/CD 但这似乎并不特别值得注意。我发现的许多示例都是用于在 Enterprise Edition 中注册应用程序。

参看。这个例子这个例子听起来很有希望和可能。

我尝试使用以下内容查询 gitlab.com:

<a href="https://gitlab.com/authorize?response_type=code
     &redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Foauth-redirect&client_id=<provided by gitlab.com>&state=<Not sure where this is explained>">Connect Your Account</a>

似乎参数的顺序比我想象的更重要。一个有效的查询是: https://gitlab.com/oauth/authorize?client_id=<from gitlab>&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fredirect&response_type=code&state=bob&scope=profile

其中,&redirect_uri=是提供给 gitlab.com 的 URL,
并且state是一些唯一值,例如state=bobstate=hashlib.sha256(os.urandom(1024)).hexdigest()

Gitlab.com 然后回应:

http://localhost:4200/oauth-redirect

创建了一个 Angular 服务,即ng g s oauth-redirect返回值然后使用 Angular 回调魔法进行解析,例如这里描述的

目前的症结所在:

如何正确解析并重定向到正确的网页?

标签: oauth-2.0gitlab

解决方案


推荐阅读