-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue app initiated sso to web token
ref DEV-1405
- Loading branch information
Showing
17 changed files
with
1,864 additions
and
140 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package oauth | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/authgear/authgear-server/pkg/util/clock" | ||
"github.com/authgear/authgear-server/pkg/util/duration" | ||
) | ||
|
||
const ( | ||
AppInitiatedSSOToWebTokenLifetime = duration.Short | ||
) | ||
|
||
type AppInitiatedSSOToWebToken struct { | ||
AppID string `json:"app_id"` | ||
AuthorizationID string `json:"authorization_id"` | ||
ClientID string `json:"client_id"` | ||
OfflineGrantID string `json:"offline_grant_id"` | ||
Scopes []string `json:"scopes"` | ||
|
||
CreatedAt time.Time `json:"created_at"` | ||
ExpireAt time.Time `json:"expire_at"` | ||
TokenHash string `json:"token_hash"` | ||
} | ||
|
||
type AppInitiatedSSOToWebTokenService struct { | ||
Clock clock.Clock | ||
|
||
AppInitiatedSSOToWebTokens AppInitiatedSSOToWebTokenStore | ||
} | ||
|
||
type IssueAppInitiatedSSOToWebTokenResult struct { | ||
Token string | ||
TokenHash string | ||
TokenType string | ||
ExpiresIn int | ||
} | ||
|
||
type IssueAppInitiatedSSOToWebTokenOptions struct { | ||
AppID string | ||
ClientID string | ||
OfflineGrantID string | ||
AuthorizationID string | ||
Scopes []string | ||
} | ||
|
||
func (s *AppInitiatedSSOToWebTokenService) IssueAppInitiatedSSOToWebToken( | ||
options *IssueAppInitiatedSSOToWebTokenOptions, | ||
) (*IssueAppInitiatedSSOToWebTokenResult, error) { | ||
now := s.Clock.NowUTC() | ||
token := GenerateToken() | ||
tokenHash := HashToken(token) | ||
err := s.AppInitiatedSSOToWebTokens.CreateAppInitiatedSSOToWebToken(&AppInitiatedSSOToWebToken{ | ||
AppID: options.AppID, | ||
AuthorizationID: options.AuthorizationID, | ||
ClientID: options.ClientID, | ||
OfflineGrantID: options.OfflineGrantID, | ||
Scopes: options.Scopes, | ||
|
||
CreatedAt: now, | ||
ExpireAt: now.Add(AppInitiatedSSOToWebTokenLifetime), | ||
TokenHash: tokenHash, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &IssueAppInitiatedSSOToWebTokenResult{ | ||
Token: token, | ||
TokenHash: tokenHash, | ||
TokenType: "Bearer", | ||
ExpiresIn: int(AppInitiatedSSOToWebTokenLifetime.Seconds()), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.