Skip to content

Commit 02386df

Browse files
committed
Add document detail
1 parent fdbdb7f commit 02386df

File tree

5 files changed

+470
-9
lines changed

5 files changed

+470
-9
lines changed

css/font.css

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/* cyrillic-ext */
2+
@font-face {
3+
font-family: 'Open Sans';
4+
font-style: normal;
5+
font-weight: 400;
6+
src: local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/opensans/v13/K88pR3goAWT7BTt32Z01m4X0hVgzZQUfRDuZrPvH3D8.woff2) format('woff2');
7+
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
8+
}
9+
/* cyrillic */
10+
@font-face {
11+
font-family: 'Open Sans';
12+
font-style: normal;
13+
font-weight: 400;
14+
src: local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/opensans/v13/RjgO7rYTmqiVp7vzi-Q5UYX0hVgzZQUfRDuZrPvH3D8.woff2) format('woff2');
15+
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
16+
}
17+
/* greek-ext */
18+
@font-face {
19+
font-family: 'Open Sans';
20+
font-style: normal;
21+
font-weight: 400;
22+
src: local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/opensans/v13/LWCjsQkB6EMdfHrEVqA1KYX0hVgzZQUfRDuZrPvH3D8.woff2) format('woff2');
23+
unicode-range: U+1F00-1FFF;
24+
}
25+
/* greek */
26+
@font-face {
27+
font-family: 'Open Sans';
28+
font-style: normal;
29+
font-weight: 400;
30+
src: local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/opensans/v13/xozscpT2726on7jbcb_pAoX0hVgzZQUfRDuZrPvH3D8.woff2) format('woff2');
31+
unicode-range: U+0370-03FF;
32+
}
33+
/* vietnamese */
34+
@font-face {
35+
font-family: 'Open Sans';
36+
font-style: normal;
37+
font-weight: 400;
38+
src: local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/opensans/v13/59ZRklaO5bWGqF5A9baEEYX0hVgzZQUfRDuZrPvH3D8.woff2) format('woff2');
39+
unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
40+
}
41+
/* latin-ext */
42+
@font-face {
43+
font-family: 'Open Sans';
44+
font-style: normal;
45+
font-weight: 400;
46+
src: local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/opensans/v13/u-WUoqrET9fUeobQW7jkRYX0hVgzZQUfRDuZrPvH3D8.woff2) format('woff2');
47+
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
48+
}
49+
/* latin */
50+
@font-face {
51+
font-family: 'Open Sans';
52+
font-style: normal;
53+
font-weight: 400;
54+
src: local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/opensans/v13/cJZKeOuBrn4kERxqtaUH3ZBw1xU1rKptJj_0jans920.woff2) format('woff2');
55+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
56+
}
57+
/* cyrillic-ext */
58+
@font-face {
59+
font-family: 'Open Sans';
60+
font-style: normal;
61+
font-weight: 700;
62+
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzA7aC6SjiAOpAWOKfJDfVRY.woff2) format('woff2');
63+
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
64+
}
65+
/* cyrillic */
66+
@font-face {
67+
font-family: 'Open Sans';
68+
font-style: normal;
69+
font-weight: 700;
70+
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzBdwxCXfZpKo5kWAx_74bHs.woff2) format('woff2');
71+
unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
72+
}
73+
/* greek-ext */
74+
@font-face {
75+
font-family: 'Open Sans';
76+
font-style: normal;
77+
font-weight: 700;
78+
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzJ6vnaPZw6nYDxM4SVEMFKg.woff2) format('woff2');
79+
unicode-range: U+1F00-1FFF;
80+
}
81+
/* greek */
82+
@font-face {
83+
font-family: 'Open Sans';
84+
font-style: normal;
85+
font-weight: 700;
86+
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzPy1_HTwRwgtl1cPga3Fy3Y.woff2) format('woff2');
87+
unicode-range: U+0370-03FF;
88+
}
89+
/* vietnamese */
90+
@font-face {
91+
font-family: 'Open Sans';
92+
font-style: normal;
93+
font-weight: 700;
94+
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzPgrLsWo7Jk1KvZser0olKY.woff2) format('woff2');
95+
unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
96+
}
97+
/* latin-ext */
98+
@font-face {
99+
font-family: 'Open Sans';
100+
font-style: normal;
101+
font-weight: 700;
102+
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzIjoYw3YTyktCCer_ilOlhE.woff2) format('woff2');
103+
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
104+
}
105+
/* latin */
106+
@font-face {
107+
font-family: 'Open Sans';
108+
font-style: normal;
109+
font-weight: 700;
110+
src: local('Open Sans Bold'), local('OpenSans-Bold'), url(https://fonts.gstatic.com/s/opensans/v13/k3k702ZOKiLJc3WVjuplzBampu5_7CjHW5spxoeN3Vs.woff2) format('woff2');
111+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
112+
}

css/github.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 174 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
<html lang="en-us">
33

44
<head>
5-
<meta charset="UTF-8">
6-
<title>Golang OAuth2 Server Framework</title>
5+
<title>OAuth2 Framework</title>
76
<meta name="viewport" content="width=device-width, initial-scale=1">
87
<meta name="theme-color" content="#157878">
8+
<meta name="description" content="Golang OAuth2 Server Framework" />
9+
<meta name="keywords" content="oauth 2.0, oauth2, oauth, golang oauth2" />
910
<link rel="stylesheet" href="css/normalize.css">
10-
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
11+
<link rel="stylesheet" href="css/font.css">
1112
<link rel="stylesheet" href="css/cayman.css">
1213
</head>
1314

@@ -20,9 +21,178 @@ <h2 class="project-tagline">A simple help you build the 2.0 service framework</h
2021
</section>
2122

2223
<section class="main-content">
24+
<h1>1. Begin to use</h1>
25+
26+
<h2>1.1 Create a Manager instance</h2>
27+
<blockquote>
28+
<p>import "gopkg.in/oauth2.v3/manage"</p>
29+
</blockquote>
30+
<pre><code class="go">manager := manage.NewManager()</code></pre>
31+
32+
<h3>1.1.1 Manager of the configuration parameters</h3>
33+
34+
<h4>1.1.1.1 SetAuthorizeCodeExp set the authorization code expiration time</h4>
35+
<pre><code class="go">manager.SetAuthorizeCodeExp(time.Minute * 10)</code></pre>
36+
37+
<h4>1.1.1.2 SetAuthorizeCodeTokenCfg set the authorization code grant token config</h4>
38+
<pre><code class="go">
39+
cfg := &manage.Config{
40+
// access token expiration time
41+
AccessTokenExp: time.Hour * 2,
42+
// refresh token expiration time
43+
RefreshTokenExp: time.Hour * 24 * 3,
44+
// whether to generate the refreshing token
45+
IsGenerateRefresh: true,
46+
}
47+
manager.SetAuthorizeCodeTokenCfg(cfg)
48+
</code></pre>
49+
50+
<h4>1.1.1.3 SetImplicitTokenCfg set the implicit grant token config</h4>
51+
<pre><code class="go">
52+
cfg := &manage.Config{
53+
// access token expiration time
54+
AccessTokenExp: time.Hour * 1,
55+
}
56+
manager.SetAuthorizeCodeTokenCfg(cfg)
57+
</code></pre>
58+
59+
<h4>1.1.1.4 SetPasswordTokenCfg set the password grant token config</h4>
60+
<pre><code class="go">
61+
cfg := &manage.Config{
62+
// access token expiration time
63+
AccessTokenExp: time.Hour * 2,
64+
// refresh token expiration time
65+
RefreshTokenExp: time.Hour * 24 * 7,
66+
// whether to generate the refreshing token
67+
IsGenerateRefresh: true,
68+
}
69+
manager.SetPasswordTokenCfg(cfg)
70+
</code></pre>
71+
72+
<h4>1.1.1.5 SetClientTokenCfg set the client grant token config</h4>
73+
<pre><code class="go">
74+
cfg := &manage.Config{
75+
// access token expiration time
76+
AccessTokenExp: time.Hour * 2,
77+
}
78+
manager.SetClientTokenCfg(cfg)
79+
</code></pre>
80+
81+
<h4>1.1.1.6 SetRefreshTokenCfg set the refreshing token config</h4>
82+
<pre><code class="go">
83+
cfg := &manage.Config{
84+
// whether to generate the refreshing token
85+
IsGenerateRefresh: false,
86+
}
87+
manager.SetRefreshTokenCfg(cfg)
88+
</code></pre>
89+
90+
<h3>1.1.2 The Manager of the interface map</h3>
91+
92+
<h4>1.1.2.1 MapTokenModel mapping the token information model</h4>
93+
<blockquote>
94+
<p>import "gopkg.in/oauth2.v3/models"</p>
95+
</blockquote>
96+
<pre><code class="go">manager.MapTokenModel(models.NewToken())</code></pre>
97+
98+
<h4>1.1.2.2 MapAuthorizeGenerate mapping the authorize code generate interface</h4>
99+
<blockquote>
100+
<p>import "gopkg.in/oauth2.v3/generates"</p>
101+
</blockquote>
102+
<pre><code class="go">manager.MapAuthorizeGenerate(generates.NewAuthorizeGenerate())</code></pre>
103+
104+
<h4>1.1.2.3 MapAccessGenerate mapping the access token generate interface</h4>
105+
<blockquote>
106+
<p>import "gopkg.in/oauth2.v3/generates"</p>
107+
</blockquote>
108+
<pre><code class="go">manager.MapAccessGenerate(generates.NewAccessGenerate())</code></pre>
109+
110+
<h4>1.1.2.4 MustTokenStorage mandatory mapping the token store interface</h4>
111+
<blockquote>
112+
<p>import "gopkg.in/oauth2.v3/store"</p>
113+
</blockquote>
114+
<pre><code class="go">manager.MustTokenStorage(store.NewMemoryTokenStore())</code></pre>
115+
116+
<h4>1.1.2.5 MapClientStorage mapping the client store interface</h4>
117+
<blockquote>
118+
<p>Client information storage, need to be determined according to the specific business scenarios, here temporarily does not provide specific implementation</p>
119+
</blockquote>
120+
121+
<h2>1.2 Create a Server instance</h2>
122+
<blockquote>
123+
<p>import "gopkg.in/oauth2.v3/server"</p>
124+
</blockquote>
125+
<pre><code class="go">srv := server.NewServer(server.NewConfig(), manager)</code></pre>
126+
127+
<h3>1.2.1 Server configuration parameters</h3>
128+
<h4>1.2.1.1 SetAllowedResponseType allow the authorization types</h4>
129+
<blockquote>
130+
<p>The types of authorization support:Code,Token</p>
131+
</blockquote>
132+
133+
<h4>1.2.1.1 SetAllowedGrantType allow the grant types</h4>
134+
<blockquote>
135+
<p>Support authorization model:AuthorizationCode,PasswordCredentials,ClientCredentials,Refreshing</p>
136+
</blockquote>
137+
138+
<h3>1.2.2 Server processing function</h3>
139+
140+
<h4>1.2.2.1 SetClientInfoHandler get client info from request(The default support:ClientFormHandler,ClientBasicHandler)</h4>
141+
<pre><code class="go">ClientInfoHandler func(r *http.Request) (clientID, clientSecret string, err error)</code></pre>
142+
143+
<h4>1.2.2.2 SetClientAuthorizedHandler check the client allows to use this authorization grant type</h4>
144+
<pre><code class="go">ClientAuthorizedHandler func(clientID string, grant oauth2.GrantType) (allowed bool, err error)</code></pre>
145+
146+
<h4>1.2.2.3 SetClientScopeHandler check the client allows to use scope</h4>
147+
<pre><code class="go">ClientScopeHandler func(clientID, scope string) (allowed bool, err error)</code></pre>
148+
149+
<h4>1.2.2.4 SetUserAuthorizationHandler get user id from request authorization</h4>
150+
<pre><code class="go">UserAuthorizationHandler func(w http.ResponseWriter, r *http.Request) (userID string, err error)</code></pre>
151+
152+
<h4>1.2.2.5 SetPasswordAuthorizationHandler get user id from username and password</h4>
153+
<pre><code class="go">PasswordAuthorizationHandler func(username, password string) (userID string, err error)</code></pre>
154+
155+
<h4>1.2.2.6 SetRefreshingScopeHandler check the scope of the refreshing token</h4>
156+
<pre><code class="go">RefreshingScopeHandler func(newScope, oldScope string) (allowed bool, err error)</code></pre>
157+
158+
<h4>1.2.2.7 SetResponseErrorHandler response error handing</h4>
159+
<pre><code class="go">ResponseErrorHandler func(re *errors.Response)</code></pre>
160+
161+
<h4>1.2.2.8 SetInternalErrorHandler internal error handing</h4>
162+
<pre><code class="go">InternalErrorHandler func(r *http.Request, err error)</code></pre>
163+
164+
<h4>1.2.2.9 SetExtensionFieldsHandler in response to the access token with the extension of the field</h4>
165+
<pre><code class="go">ExtensionFieldsHandler func(ti oauth2.TokenInfo) (fieldsValue map[string]interface{})</code></pre>
166+
167+
<h4>1.2.2.10 SetAccessTokenExpHandler set expiration date for the access token</h4>
168+
<pre><code class="go">AccessTokenExpHandler func(w http.ResponseWriter, r *http.Request) (exp time.Duration, err error)</code></pre>
169+
170+
<h4>1.2.2.11 SetAuthorizeScopeHandler set the authorized scope</h4>
171+
<pre><code class="go">AuthorizeScopeHandler func(w http.ResponseWriter, r *http.Request) (scope string, err error)</code></pre>
172+
173+
<h2>1.3 Create the HTTP listener service</h2>
174+
175+
<h3>1.3.1 The authorization request processing</h3>
176+
<pre><code class="go">
177+
http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) {
178+
err := srv.HandleAuthorizeRequest(w, r)
179+
if err != nil {
180+
http.Error(w, err.Error(), http.StatusBadRequest)
181+
}
182+
})
183+
</code></pre>
184+
185+
<h3>1.3.2 The token request processing</h3>
186+
<pre><code class="go">
187+
http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
188+
err := srv.HandleTokenRequest(w, r)
189+
if err != nil {
190+
http.Error(w, err.Error(), http.StatusBadRequest)
191+
}
192+
})
193+
</code></pre>
23194

24195
<footer class="site-footer">
25-
<span class="site-footer-owner"><a href="https://github.com/jasonlong/cayman-theme">Cayman</a> is maintained by <a href="https://github.com/jasonlong">jasonlong</a>.</span>
26196
<span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the <a href="https://github.com/jasonlong/cayman-theme">Cayman theme</a> by <a href="https://twitter.com/jasonlong">Jason Long</a>.</span>
27197
</footer>
28198

js/highlight.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)