可通过API访问的服务器数据库中的slugs:
{slug: "john-smith",type: "user"}
{slug: "microsoft-technologies",type: "company"}
Run Code Online (Sandbox Code Playgroud)
场景1:用户视图和控制器:http:// localhost/john-smith
.state('user', {
url: '/:user',
templateUrl: 'partial-user.html',
controller: 'userCtrl'
})
Run Code Online (Sandbox Code Playgroud)
方案2:公司视图和控制器:http:// localhost/microsoft-technologies
.state('company', {
url: '/:company',
templateUrl: 'partial-company.html',
controller: 'companyCtrl'
})
Run Code Online (Sandbox Code Playgroud)
现在我想基于从API调用到服务器的slug做一个动态状态.
我写了一个虚构的代码.但我没有办法实现
// Example URL http://localhost/john-smith
.state('hybrid', {
// /john-smith
url: '/:slug',
templateUrl: function () {
return "partial-"+type+".html"
},
controllerProvider: function (rt) {
return type+'Controller'
},
resolove: {
type: function ($http, $stateParams) {
$http.get({
method: "GET",
url: "http://localhost/api/" + $stateParams.slug
}).success(function(response, status, headers, config){
//response …Run Code Online (Sandbox Code Playgroud) 使用https://github.com/thomseddon/node-oauth2-server在NodeJS中实现OAuth服务器时
我正在尝试了解OAuth 2.0的流程
不知怎的,我在这个npm包实现方面取得了成功,但我怀疑,出了点问题.
我会解释我是如何成功的.
第一次请求:
POST: http://localhost:3000/oauth/token
grant_type=password
client_id=1011
client_secret=somesecret
username=admin
password=admin
Run Code Online (Sandbox Code Playgroud)
第一回应:
{
token_type: "bearer"
access_token: "7f5261011fb0f84a4e193889fff4b7478f2a4cb2"
expires_in: 3600
refresh_token: "da83de41966979ced65b3841e1758335a811c0c2"
}
Run Code Online (Sandbox Code Playgroud)
获得访问令牌后,我正在发送另一个http调用
第二次请求:
GET http://localhost:3000/secret
Authorization: Bearer 7f5261011fb0f84a4e193889fff4b7478f2a4cb2
Run Code Online (Sandbox Code Playgroud)
第二回应:
{"data":"Secret area accessible"}
Run Code Online (Sandbox Code Playgroud)
但在这里我完全感到困惑
问题1.缺少Authorization_code部分
问题2.在第一次调用时我需要发送client_secret和user_password - 如果我发送两个意味着oauth客户端向用户公开秘密(浏览器)或者用户向OAuth客户端提供密码.
如果整个OAuth 2.0的任何请求/响应模式如下,请与我分享
a. browser -> oauth server POST /oauth/authorize?client_id,username,password
b. USER GRANTS PERMISSION
c. browser -> oauth server RESPONSE auth_code
d. browser -> oauth client POST auth_code
e. oauth_client -> oauth server POST auth_code
e. oauth server -> …Run Code Online (Sandbox Code Playgroud) 我安装了 dgraph gru 进行采访
go get github.com/dgraph-io/gru
cd $GOPATH/src/github.com/dgraph-io/gru
git checkout develop
go build . && ./gru -user=admin -pass=pass -secret=0a45e5eGseF41o0719PJ39KljMK4F4v2
docker run -it -p 127.0.0.1:8088:8080 -p 127.0.0.1:9080:9080 -v ~/dgraph:/dgraph --name dgraph dgraph/dgraph:v0.7.5 dgraph --bindall=true
Run Code Online (Sandbox Code Playgroud)
当我尝试创建测验或问题时出现以下错误
Aug 09 10:14:23 gru[16999]: [negroni] Completed 500 Internal Server Error in 30.001305978s
Aug 09 10:14:24 gru[16999]: [negroni] Completed 500 Internal Server Error in 30.000762875s
Aug 09 10:19:40 gru[16999]: Error while rejecting candidates: Couldn't get response from Dgraph: Post http://localhost:8088/query: dial tcp 127.0.0.1:8088: i/o timeout[negroni] Started …Run Code Online (Sandbox Code Playgroud)