Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-NRF
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-NRF
Commits
02e9fb5b
Commit
02e9fb5b
authored
Dec 28, 2020
by
Tien-Thinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generate signature for OAuth2 authorization
parent
011c9ac8
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
234 additions
and
114 deletions
+234
-114
src/api-server/api/AccessTokenRequestApi.cpp
src/api-server/api/AccessTokenRequestApi.cpp
+1
-1
src/api-server/impl/AccessTokenRequestApiImpl.cpp
src/api-server/impl/AccessTokenRequestApiImpl.cpp
+39
-13
src/nrf_app/nrf_app.cpp
src/nrf_app/nrf_app.cpp
+124
-81
src/nrf_app/nrf_app.hpp
src/nrf_app/nrf_app.hpp
+16
-0
src/nrf_app/nrf_jwt.cpp
src/nrf_app/nrf_jwt.cpp
+43
-15
src/nrf_app/nrf_jwt.hpp
src/nrf_app/nrf_jwt.hpp
+7
-3
yaml/cmd.txt
yaml/cmd.txt
+4
-1
No files found.
src/api-server/api/AccessTokenRequestApi.cpp
View file @
02e9fb5b
...
...
@@ -34,7 +34,7 @@ void AccessTokenRequestApi::init() {
void
AccessTokenRequestApi
::
setupRoutes
()
{
using
namespace
Pistache
::
Rest
;
Routes
::
Post
(
*
router
,
base
+
nrf_cfg
.
sbi_api_version
+
"/oauth2/token"
,
Routes
::
bind
(
&
AccessTokenRequestApi
::
access_token_request_handler
,
this
));
Routes
::
Post
(
*
router
,
base
+
"/oauth2/token"
,
Routes
::
bind
(
&
AccessTokenRequestApi
::
access_token_request_handler
,
this
));
// Default handler, called when a route is not found
router
->
addCustomHandler
(
Routes
::
bind
(
&
AccessTokenRequestApi
::
access_token_request_api_default_handler
,
this
));
...
...
src/api-server/impl/AccessTokenRequestApiImpl.cpp
View file @
02e9fb5b
/**
* NRF OAuth2
* NRF OAuth2 Authorization. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
* NRF OAuth2 Authorization. © 2019, 3GPP Organizational Partners (ARIB, ATIS,
* CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.0.2
*
*
* NOTE: This class is auto generated by OpenAPI Generator
(https://openapi-generator.tech).
*
https://openapi-generator.tech
*
Do not edit
the class manually.
* NOTE: This class is auto generated by OpenAPI Generator
*
(https://openapi-generator.tech). https://openapi-generator.tech Do not edit
* the class manually.
*/
#include "AccessTokenRequestApiImpl.h"
#include "3gpp_29.500.h"
#include "AccessTokenRsp.h"
#include "Helpers.h"
#include "logger.hpp"
namespace
oai
{
namespace
nrf
{
...
...
@@ -18,23 +23,44 @@ namespace api {
using
namespace
oai
::
nrf
::
model
;
using
namespace
oai
::
nrf
::
app
;
using
namespace
oai
::
nrf
::
helpers
;
AccessTokenRequestApiImpl
::
AccessTokenRequestApiImpl
(
std
::
shared_ptr
<
Pistache
::
Rest
::
Router
>
rtr
,
nrf_app
*
nrf_app_inst
,
std
::
string
address
)
:
AccessTokenRequestApi
(
rtr
),
m_nrf_app
(
nrf_app_inst
),
m_address
(
address
)
{
}
:
AccessTokenRequestApi
(
rtr
),
m_nrf_app
(
nrf_app_inst
),
m_address
(
address
)
{}
void
AccessTokenRequestApiImpl
::
access_token_request
(
const
Pistache
::
Rest
::
Request
&
request
,
Pistache
::
Http
::
ResponseWriter
&
response
)
{
response
.
send
(
Pistache
::
Http
::
Code
::
Ok
,
"Do some magic
\n
"
);
}
Logger
::
nrf_sbi
().
info
(
"Got a request to request an OAuth2 access token from the authorization "
"server (NRF)"
);
}
}
Logger
::
nrf_sbi
().
info
(
"request body %s"
,
request
.
body
().
c_str
());
int
http_code
=
0
;
ProblemDetails
problem_details
=
{};
AccessTokenRsp
access_token_rsp
=
{};
m_nrf_app
->
handle_access_token_request
(
request
.
body
(),
access_token_rsp
,
http_code
,
1
,
problem_details
);
nlohmann
::
json
json_data
=
{};
std
::
string
content_type
=
"application/json"
;
if
(
http_code
!=
HTTP_STATUS_CODE_200_OK
)
{
to_json
(
json_data
,
problem_details
);
content_type
=
"application/problem+json"
;
}
else
{
to_json
(
json_data
,
access_token_rsp
);
}
// content type
response
.
headers
().
add
<
Pistache
::
Http
::
Header
::
ContentType
>
(
Pistache
::
Http
::
Mime
::
MediaType
(
content_type
));
response
.
send
(
Pistache
::
Http
::
Code
(
http_code
),
json_data
.
dump
().
c_str
());
}
}
// namespace api
}
// namespace nrf
}
// namespace oai
src/nrf_app/nrf_app.cpp
View file @
02e9fb5b
This diff is collapsed.
Click to expand it.
src/nrf_app/nrf_app.hpp
View file @
02e9fb5b
...
...
@@ -35,12 +35,14 @@
#include "PatchItem.h"
#include "ProblemDetails.h"
#include "SubscriptionData.h"
#include "AccessTokenRsp.h"
#include "nrf_event.hpp"
#include "nrf_profile.hpp"
#include "nrf_search_result.hpp"
#include "nrf_subscription.hpp"
#include "uint_generator.hpp"
namespace
oai
{
namespace
nrf
{
namespace
app
{
...
...
@@ -193,6 +195,20 @@ class nrf_app {
int
&
http_code
,
const
uint8_t
http_version
,
ProblemDetails
&
problem_details
);
/*
* Handle a Register NF Instance request
* @param [const std::string &] request_body: includes access token request
* @param [AccessTokenRsp &] access_token_rsp: Access token response
* @param [int &] http_code: HTTP code used to return to the consumer
* @param [const uint8_t] http_version: HTTP version
* @param [ProblemDetails &] problem_details: Store details of the error
* @return void
*/
void
handle_access_token_request
(
const
std
::
string
&
request_body
,
AccessTokenRsp
&
access_token_rsp
,
int
&
http_code
,
const
uint8_t
http_version
,
ProblemDetails
&
problem_details
);
/*
* Insert a nrf profile
* @param [const std::string &] profile_id: Profile ID
...
...
src/nrf_app/nrf_jwt.cpp
View file @
02e9fb5b
...
...
@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
file
*
except in compliance with the License.
*
You may obtain a copy of the
License at
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*
file except in compliance with the License. You may obtain a copy of the
*License at
*
* http://www.openairinterface.org/?page_id=698
*
...
...
@@ -30,24 +30,52 @@
#include "nrf_jwt.hpp"
#include <iostream>
#include "jwt/jwt.hpp"
using
namespace
oai
::
nrf
::
app
;
void
nrf_jwt
::
test_jwt
(){
//------------------------------------------------------------------------------
bool
nrf_jwt
::
generate_signature
(
const
std
::
string
&
nf_consumer_id
,
std
::
string
&
signature
)
const
{
std
::
string
key
;
get_secret_key
(
nf_consumer_id
,
key
);
// Create JWT object
//TODO
jwt
::
jwt_object
obj
{
jwt
::
params
::
algorithm
(
"HS256"
),
jwt
::
params
::
payload
({{
"iss"
,
"nrf_instance_id"
},
{
"sub"
,
"nf_consumer_id"
},
{
"aud"
,
"nf_producer_id"
},
{
"scope"
,
"nf_producer_name"
},
{
"exp"
,
"100"
}}),
jwt
::
params
::
secret
(
key
)};
// Get the encoded string/assertion
signature
=
obj
.
signature
();
}
//------------------------------------------------------------------------------
bool
nrf_jwt
::
get_secret_key
(
const
std
::
string
&
nf_consumer_id
,
std
::
string
&
key
)
const
{
// TODO:
key
=
"secret"
;
}
//------------------------------------------------------------------------------
void
nrf_jwt
::
test_jwt
()
{
using
namespace
jwt
::
params
;
auto
key
=
"secret"
;
//Secret to use for the algorithm
//Create JWT object
jwt
::
jwt_object
obj
{
algorithm
(
"HS256"
),
payload
({{
"some"
,
"payload"
}}),
secret
(
key
)};
auto
key
=
"secret"
;
// Secret to use for the algorithm
// Create JWT object
jwt
::
jwt_object
obj
{
algorithm
(
"HS256"
),
payload
({{
"some"
,
"payload"
}}),
secret
(
key
)};
//
Get the encoded string/assertion
//
Get the encoded string/assertion
auto
enc_str
=
obj
.
signature
();
std
::
cout
<<
enc_str
<<
std
::
endl
;
//
Decode
//
Decode
auto
dec_obj
=
jwt
::
decode
(
enc_str
,
algorithms
({
"HS256"
}),
secret
(
key
));
std
::
cout
<<
dec_obj
.
header
()
<<
std
::
endl
;
std
::
cout
<<
dec_obj
.
payload
()
<<
std
::
endl
;
}
src/nrf_app/nrf_jwt.hpp
View file @
02e9fb5b
...
...
@@ -30,16 +30,20 @@
#ifndef FILE_NRF_JWT_HPP_SEEN
#define FILE_NRF_JWT_HPP_SEEN
#include <string>
namespace
oai
{
namespace
nrf
{
namespace
app
{
class
nrf_jwt
{
private:
public:
void
test_jwt
();
bool
generate_signature
(
const
std
::
string
&
nf_consumer_id
,
std
::
string
&
signature
)
const
;
bool
get_secret_key
(
const
std
::
string
&
nf_consumer_id
,
std
::
string
&
key
)
const
;
};
}
// namespace app
...
...
yaml/cmd.txt
View file @
02e9fb5b
...
...
@@ -16,3 +16,6 @@ curl -X PATCH -H "Content-Type: application/json" http://192.168.1.23/nnrf-nfm/v
curl -X GET "http://192.168.1.23/nnrf-disc/v1//nf-instances?target-nf-type="AMF"&requester-nf-type="AMF""
#Access Token
curl -d "grant_type=client_credentials&nfInstanceId=343a924e-6494-4927-860b-d45692c95c2d&scope=nf_name" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://192.168.1.23/oauth2/token
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment