Skip to content

Commit 8c2bf6e

Browse files
committed
fix: add token information in redirect url
1 parent 57bc091 commit 8c2bf6e

26 files changed

+440
-225
lines changed

app/package-lock.json

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

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"author": "Lakhan Samani",
1212
"license": "ISC",
1313
"dependencies": {
14-
"@authorizerdev/authorizer-react": "latest",
14+
"@authorizerdev/authorizer-react": "0.9.0-beta.0",
1515
"@types/react": "^17.0.15",
1616
"@types/react-dom": "^17.0.9",
1717
"esbuild": "^0.12.17",

app/src/App.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import Root from './Root';
66
export default function App() {
77
// @ts-ignore
88
const globalState: Record<string, string> = window['__authorizer__'];
9-
if (globalState.state) {
10-
sessionStorage.setItem('authorizer_state', globalState.state);
11-
}
129
return (
1310
<div
1411
style={{
@@ -33,15 +30,7 @@ export default function App() {
3330
/>
3431
<h1>{globalState.organizationName}</h1>
3532
</div>
36-
<div
37-
style={{
38-
width: 400,
39-
margin: `10px auto`,
40-
border: `1px solid #D1D5DB`,
41-
padding: `25px 20px`,
42-
borderRadius: 5,
43-
}}
44-
>
33+
<div className="container">
4534
<BrowserRouter>
4635
<AuthorizerProvider
4736
config={{

app/src/Root.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ export default function Root() {
1111

1212
useEffect(() => {
1313
if (token) {
14-
const state = sessionStorage.getItem('authorizer_state')?.trim();
15-
const url = new URL(config.redirectURL || '/app');
14+
console.log({ token });
15+
let redirectURL = config.redirectURL || '/app';
16+
const params = `access_token=${token.access_token}&id_token=${token.id_token}&expires_in=${token.expires_in}&refresh_token=${token.refresh_token}`;
17+
const url = new URL(redirectURL);
18+
if (redirectURL.includes('?')) {
19+
redirectURL = `${redirectURL}&${params}`;
20+
} else {
21+
redirectURL = `${redirectURL}?${params}`;
22+
}
23+
1624
if (url.origin !== window.location.origin) {
17-
console.log({ x: `${config.redirectURL || '/app'}?state=${state}` });
1825
sessionStorage.removeItem('authorizer_state');
19-
window.location.replace(
20-
`${config.redirectURL || '/app'}?state=${state}`
21-
);
26+
window.location.replace(redirectURL);
2227
}
2328
}
2429
return () => {};

app/src/index.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
body {
2-
margin: 0;
2+
margin: 10;
33
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
44
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
55
sans-serif;
@@ -14,3 +14,17 @@ body {
1414
*:after {
1515
box-sizing: inherit;
1616
}
17+
18+
.container {
19+
box-sizing: content-box;
20+
border: 1px solid #d1d5db;
21+
padding: 25px 20px;
22+
border-radius: 5px;
23+
}
24+
25+
@media only screen and (min-width: 768px) {
26+
.container {
27+
width: 400px;
28+
margin: 0 auto;
29+
}
30+
}

server/db/models/verification_requests.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,28 @@ import "github.com/authorizerdev/authorizer/server/graph/model"
44

55
// VerificationRequest model for db
66
type VerificationRequest struct {
7-
Key string `json:"_key,omitempty" bson:"_key"` // for arangodb
8-
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id"`
9-
Token string `gorm:"type:text" json:"token" bson:"token"`
10-
Identifier string `gorm:"uniqueIndex:idx_email_identifier" json:"identifier" bson:"identifier"`
11-
ExpiresAt int64 `json:"expires_at" bson:"expires_at"`
12-
CreatedAt int64 `json:"created_at" bson:"created_at"`
13-
UpdatedAt int64 `json:"updated_at" bson:"updated_at"`
14-
Email string `gorm:"uniqueIndex:idx_email_identifier" json:"email" bson:"email"`
15-
Nonce string `gorm:"type:char(36)" json:"nonce" bson:"nonce"`
7+
Key string `json:"_key,omitempty" bson:"_key"` // for arangodb
8+
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id"`
9+
Token string `gorm:"type:text" json:"token" bson:"token"`
10+
Identifier string `gorm:"uniqueIndex:idx_email_identifier" json:"identifier" bson:"identifier"`
11+
ExpiresAt int64 `json:"expires_at" bson:"expires_at"`
12+
CreatedAt int64 `json:"created_at" bson:"created_at"`
13+
UpdatedAt int64 `json:"updated_at" bson:"updated_at"`
14+
Email string `gorm:"uniqueIndex:idx_email_identifier" json:"email" bson:"email"`
15+
Nonce string `gorm:"type:char(36)" json:"nonce" bson:"nonce"`
16+
RedirectURI string `gorm:"type:text" json:"redirect_uri" bson:"redirect_uri"`
1617
}
1718

1819
func (v *VerificationRequest) AsAPIVerificationRequest() *model.VerificationRequest {
1920
return &model.VerificationRequest{
20-
ID: v.ID,
21-
Token: &v.Token,
22-
Identifier: &v.Identifier,
23-
Expires: &v.ExpiresAt,
24-
CreatedAt: &v.CreatedAt,
25-
UpdatedAt: &v.UpdatedAt,
26-
Email: &v.Email,
21+
ID: v.ID,
22+
Token: &v.Token,
23+
Identifier: &v.Identifier,
24+
Expires: &v.ExpiresAt,
25+
CreatedAt: &v.CreatedAt,
26+
UpdatedAt: &v.UpdatedAt,
27+
Email: &v.Email,
28+
Nonce: &v.Nonce,
29+
RedirectURI: &v.RedirectURI,
2730
}
2831
}

server/graph/generated/generated.go

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

0 commit comments

Comments
 (0)